Loading module outside zend framework - zend-framework

I am using ZEND 3 and I need to use a module in ordinary PHP file outside framework. How can it be done - make instance of the module and call some method, please?

Related

Trying to use Zend Escaper from ZF 2.1 in Zend Framework 1.11.11

I am trying to use the Zend Escaper class from Zend Framework 2.2 in Zend Framework 1.11.11 by copying the Escaper folder from the ZF 2.2 into ZF 1.11.11. I am trying to do this becuase in the Zend Escaper class documentation it says that the class is a stand-alone class and is not dependent on any of the other Zend classes/interfaces.
But once I added the folder into our ZF 1.11.11 library and tried instantiating the Zend Escaper class and load the web page all I am seeing is an empty page. I am unable to debug this. I tried to print the object that is returned on instanitation using print_r but that did not work.
Our application is built on ZF 1.11.11, switching to ZF 2.2 is a huge risk for us and would be a major change to our application. That is why I am trying to do this.
Please help me know whether it is possible to make Zend Escaper class work in ZF 1.11.11 in the way I am trying to do. If so, why am I getting this problem.
Also, is there any class in ZF 1.11.11 that I could use for encoding/escaping.

Zend Framework 1.11: how to autoload a class that uses namespaces

I have a Zend Framework 1.11 application, and I want to use a package called RandomLib. The problem is, it doesn't have an autoloader, and I've tried reading the Zend documentation on using autoloaders, but I can't make sense of it.
I've placed the RandomLib folder in my library directory. What kind of code would I need in my Bootstrap.php file to autoload the class?
Starting in version 1.10.0, Zend Framework now allows loading classes from PHP namespaces. This support follows the same guidelines and implementation as that found in the ยป PHP Framework Interop Group PSR-0 reference implementation. Source
Put content of RandomLib/lib under library/RandomLib
In application.ini add autoloaderNamespaces[] = "RandomLib"
If you wish you can include namespace libraries directly in your Bootstrap.php file after you moved the library in "library/MyExternalLib"
protected function _initAutoLoader()
{
$loader = Zend_Loader_Autoloader::getInstance();
$loader->registerNamespace('MyExternalLib');
return $loader;
}

url for an action of a controller in zend framework

I am trying to learning Zend framework. For that I have installed NetBeans IDE and download zend framework's library. I have created one small application by NetBeans IDE and place the zend framework's library under library folder.
Under Controller folder, in IndexController.php file, I have written one action called indexAction() and there I write simply $this->view->assign('title', 'Hello, World!');.
Under views/scripts/index folder create one file called index.phtml and there I have written out <h1><?php echo $this->escape($this->title); ?></h1>.
My main folder name is phpproject1 and under that I have created all other folders like application, library,public.
Now please suggest me how to open that action in browser?
e.g. - In codeigniter it is like : localhost://project_name/index.php/controller_name/action_name
Thanks in advance.
I assume your installation is correct and you didn't configure any route. try to adapte this to your case.
http://lcalhost/[project_Name]/public/[Module_name]/[Controller_name]/[action_name]
in case you dont have Module;
http://lcalhost/[project_Name]/public/[Controller_name]/[action_name]

$this->getInvokeArg('bootstrap')->getOptions(); fails when called from Zend Helper file - why?

using ...
$this->getInvokeArg('bootstrap')->getOptions();
.. to retrieve my config settings from application.ini (using Zend Framework 1.11). this is failing when called from a Zend Helper file but works when called in a controller
why?
The getInvokeArg() method exists for controllers (classes extending Zend_Controller_Action), but is not available for action helpers (classes extending Zend_Controller_Action_Helper_Abstract - I suppose that is what you mean with "Zend Helper file"). You can confirm this in the Zend Framework API, which is a very useful reference when developing with the Zend Framework.
To call getInvokeArg() within an action helper, you must first get the current action controller, which you can do within action helpers by calling the getActionController() method. Concluding, within an action helper, the following code will do what you want:
$this->getActionController()->getInvokeArg('bootstrap')->getOptions();
The $this keyword refers to the current class; as such, within an action helper, $this refers to the action helper, and not the controller.

how to load models from another module in zend framework?

i am developing an application using zend framework.
i have two modules, admin and default, and each of them has their specific model directory.
i want to know, if i can instantiate a model in admin module from within default module and if this approach has problem regarding to the MVC model.
thx in advance.
So long as youve set up the Zend_Application_Resource_Modules or something pretty equivalent all you models should be registerd with the autoloader via the Zend_Application_Module_Autoloader that the modules resources registers. In short, if you follow the default way of doing things, then Models from all modules will be set up for Autoloading in the bootstrap phase.
About Zend Application and Resources
You can call get_class(): http://us3.php.net/get_class
There's possibly a more zend like way to do it, but I don't know. Check the docs.
What about call via object?
Like inter-connect two model functions in controller.
$contacts = new Model_DbTable_Contactsmdl(); // Model file in contact module
$update_id = $contacts->updateContacts($cn_id', $responsearray);
This code inside my syncController.
So you can handle admin / model function in default / controller.