Class Sofzo_From not found error when implementing Sozfo TinyMCE solution - forms

I'm trying to implement TinyMCE to text areas using the solution mentioned in Sofzo. But when I try to extend the Sofzo_Form I get the following error :
Fatal error: Class 'Sozfo_Form' not found in /home/foldername/public_html/application/forms/PageForm.php on line 4
What I have done so far -
Uploaded the Sofzo files to library with following directory structure
/library
../Sozfo
../Form.php
../../Form
../../../Element
../../../../TinyMce.php
../../View
../../../Helper
../../../Exception.php
../../../../FormTinyMce.php
../../../../TinyMce.php
Loaded the classes in application.ini as
Autoloadnamaspaces[] = "Sofzo_"
And in bootstrap as
$autoLoader = Zend_Loader_Autoloader::getInstance();
$autoLoader->registerNamespace('Zend_');
$autoLoader->registerNamespace('SF_');
$autoLoader->registerNamespace('CMS_');
$autoLoader->registerNamespace('Sofzo_');
$loader = new Zend_Loader_PluginLoader();
$loader->addPrefixPath('Zend_View_Helper', 'Zend/View/Helper/')
->addPrefixPath('Storefront_View_Helper',
'application/modules/storefront/views/helpers')
->addPrefixPath('Sozfo_Form', 'Sozfo/');
$view=new Zend_View();
$view->addHelperPath('Sozfo/View/Helper', 'Sozfo_View_Helper');
But when I try to extent the Sofzo_Form in Page_Form as
class Form_PageForm extends Sozfo_Form { }
This issue was solved thanks to Tim Fountain. But now when I load an element as
$this->addElement('tinyMce', 'message', array(
'label' => 'Message',
'required' => true,
'cols' => '50',
'rows' => '10',
'editorOptions' => new Zend_Config_Ini(APPLICATION_PATH . '/configs/tinymce.ini', 'moderator')
));
I get the following error
Plugin by name 'FormTinyMce' was not found in the registry
Read through several comments in original site and they are said to add
$view->addHelperPath('Sozfo/View/Helper', 'Sozfo_View_Helper');
to bootstrap. I've already done that, but I'm guessing I'm not doing something right. Help is much appreciated.

I think the issue is ZF can't find the class because it doesn't know about the Sozfo_ namespace. You've attempted to register this namespace in two different ways, but both of them are incorrect.
In application.ini, you have:
Autoloadnamaspaces[] = "Sofzo_"
But this should be:
autoloaderNamespaces[] = "Sozfo_"
Then in the bootstrap you've tried to register it with:
$autoLoader->registerNamespace('Sofzo_');
but presumably this should be:
$autoLoader->registerNamespace('Sozfo_');
(note spelling). Which ever fix you apply you should only use one of these methods, as they do the same thing.
If it still doesn't work after that then there's an issue with your include_path.
Edit: To fix the view helper path, try this instead of the two lines you currently have:
$view = new Zend_View();
$viewRenderer = new Zend_Controller_Action_Helper_ViewRenderer($view);
$stack = Zend_Controller_Action_HelperBroker::getStack();
$stack->push($viewRenderer);
$view->addHelperPath('Sozfo/View/Helper', 'Sozfo_View_Helper');
This adds the helper path to a view object like you have but also supplies it to the view renderer (which is what renders all the view scripts). If you don't do this then the view renderer uses its own view object, so the view object you setup in the bootstrap is never used for anything.
If this doesn't work, try passing a full path as the first parameter to addHelperPath instead:
$view->addHelperPath(APPLICATION_PATH.'/../library/Sozfo/View/Helper', 'Sozfo_View_Helper');

Related

zend framework get id in /delete/2

I'm actually using zend, and I wonder how to get the id in such url :
/delete/2
I know I can do it using :
// if URL is /delete/id/2
$request->getParam('id');
But what I want is to have url like the first one /delete/2 which sounds more logical to me.
Ideas?
Thanks for your help
I think you should be able to solve this kind of problem using routes. You can create a route for
/delete/2
by adding this to for example your config.ini file:
[production]
routes.delete.route = "delete/:id"
routes.delete.defaults.controller = delete
routes.delete.defaults.action = index
routes.delete.id.reqs = "\d+"
Here you specify the URL to match, in which words starting with a colon : are variables. As you can see, you can also set requirements on your variables regex-style. In your example, id will most likely be one or more digits, resulting in a \d+ requirement on this variable.
This route will point the url to the index action of the delete controller and sets id as a GET-var. You can alter this .ini code to suit your specific needs.
The routes can be added by putting the following code inside your bootstrap:
$config = new Zend_Config_Ini('/path/to/config.ini', 'production');
$router = new Zend_Controller_Router_Rewrite();
$router->addConfig($config, 'routes');
See the docs for more information: here for the general documentation and here for the .ini approach I just described.
Try this: add the following function to your Bootstrap.php
protected function _initRoute(){
$this->bootstrap ('frontcontroller');
$front = $this->getResource('frontcontroller');
$router = $front->getRouter();
$deleteRoute = new Zend_Controller_Router_Route(
'delete/:id',
array(
'controller' => '{enter-your-controller-name-here}',
'action' => '{enter-your-action-name-here}'
)
);
$router->addRoute('delete', $deleteRoute);
}
Don't forget to replace {enter-your-controller-name-here} with controller name and {enter-your-action-name-here} with action name.
With this code added, $request->getParam('id'); should work just fine.

Zend Controller Action Helper not found

Been pulling my hair out on why this is not working. Trying to register a controller action helper following e.g. found in Zend docs, several posts here and sundry blogs. Attempts were made both in application.ini and Bootstrap.
The helper itself resides in APPLICATION_PATH . "/controllers/helpers". The file itself is called Scoping.php. In application.ini, appnamespace = "".
<?php
class Helper_Scoping extends Zend_Controller_Action_Helper_Abstract
{
public function direct()
{
// code is here
}
}
First I tried in the application.ini:
resources.frontController.actionhelperpaths.Helper = APPLICATION_PATH "/controllers/helpers"
resources.frontController.plugins.Scoping = "Helper_Scoping"
Calling the following in my controller throws an exception with the message: "Action Helper by name Scoping not found":
$this->_helper->Scoping();
Then I tried the following in my Bootstrap (I tried both "Helper" and "Helper_" based on other examples I saw):
protected function _initActionHelpers()
{
Zend_Controller_Action_HelperBroker::addPath(
APPLICATION_PATH . '/controllers/helpers',
'Helper_'
);
Zend_Controller_Action_HelperBroker::addHelper(
new Helper_Scoping()
);
}
This time I get an uncaught exception, but same idea: "Fatal error: Class 'Helper_Scoping' not found in /Users/ppjd/Sites/dbos/application/Bootstrap.php on line 116"
Since there are so many working examples out there, I figure it must me missing something silly. Please SOS.
I don't try this but I think your helper class (inside your application structure: APPLICATION_PATH . "/controllers/helpers) should be 'Zend_Controller_Action_Helper_Scoping' instead 'Helper_Scoping'.
In the event that anyone happens upon this, here is what finally worked for me: it was a namespace issue. In the Bootstrap, I made this modification ahead of the addHelper:
$rl = $this->getResourceLoader();
$rl->addResourceTypes(array(
// ...other namespace settings...
'helper' => array(
'path' => 'controllers/helpers',
'namespace' => 'Helper',
),
));
Everything worked fine after that. Hope this helps someone else.
[Sometimes I feel like I spend more time trying to finesse the framework than actual application development.]

Zend Bootstrap How do I autoload a model?

I have an auth plugin working. I am trying to add ACL to it according to the excellent video series at http://www.youtube.com/watch?v=b6qsSnLfcmE&feature=relmfu.
My problem is that when I try to register the model in Bootstrap so that I can pass the instance to the plugin, I get a server 500 error. My bootstrap looks like this...
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
protected function _initAutoload()
{
$modelLoader = new Zend_Application_Module_AutoLoader(array(
'namespace' => '',
'basePath' => APPLICATION_PATH));
$acl = new Model_SystemAcl;
$auth = Zend_Auth::getInstance();
$fc = Zend_Controller_Front::getInstance();
$fc->registerPlugin(new Plugin_AccessCheck($acl,$auth));
return $modelLoader;
}
}
It is the line:
$acl = new Model_SystemAcl;
That is causing the problem. If I comment it out (and the $acl parameter that is passed) it works fine. It appears as though somehow my system is not configured properly to load models. This is the entire Bootstrap shown in the tutorial btw. Perhaps there is something in Application.ini I need?
EDIT: Yes, SystemAcl.php exists and is in [applicationdir]/models
This is a full example for load models from the application namespace "Application"
$resourceLoader = new Zend_Loader_Autoloader_Resource(
array(
'basePath' => APPLICATION_PATH,
'namespace' => 'Application',
)
);
$resourceLoader->addResourceType('model', 'models/', 'Model');
$autoloader = Zend_Loader_Autoloader::getInstance();
$autoloader->pushAutoloader($resourceLoader);
Try to instantiate resources that may not yet have loaded i not a good practice.
You should use an Controller Plugin instead.
Based on your setup the filename of your class should be SystemAcl.php, not Model_SystemAcl.php.
if it is in application/models then i would have thought the script should be Models_SystemAcl not Model_SystemAcl (no 's'). Saying that, it is better to use plugins in the long run, rather than sticking this sort of stuff in the bootstrap. Those tutorials are good though :)

Full dynamic router in Zend Framework

By default you have the following URL-syntax in ZF: /module/controller/action. What i want, is to build an menu-system where i can use any URL I want.
Lets say I make an menu-item called 'news'. When i call http://www.site.com/news i want to have the folowing loaded:
module: news
controller: frontpage
action: display
These config-values must be configured in the database-record for the menu-item.
How can I do this in zend? I spend a lot of time searching for it, but I still can't figure out how to. Does anybody?
I'd suggest using a front controller plugin to scan your database for all the entries, create routing rules based on those entries and add them to the router (see this).
Of course caching strategy is recommended so that you don't do a lot of processing on every request.
You can create a plugin and in routeStartup define something that intercept your request and route /module/controller/action to /action, but for this all your action names must be unique :
class My_CustomRouterPlugin extends Zend_Controller_Plugin_Abstract
{
public function routeStartup(Zend_Controller_Request_Abstract $request)
{
$fc = Zend_Controller_Front::getInstance();
$action =$fc->getRequest()->getActionName();
$router = $fc->getRouter();
$model= new myModel();
$myPage = $model->getPageByAction($action);
$route = new Zend_Controller_Router_Route('/action', array(
'module' => $myPage->getModule();
'controller' => $myPage->getController();
'action' => $action;
));
$router->addRoute($action, $route);
return $router;
}
}
In myModel define a method can get you an object(or an array) that contains module, controller names (from you DB ).
and register this plugin in your bootstrap:
$front->registerPlugin(new My_CustomRouterPlugin());

Zend Route Regex and invalid controller

php i have method to add routes:
public function addRoutes()
{
$front = Zend_Controller_Front::getInstance();
$redirect = $front->getRouter();
$router = new Zend_Controller_Router_Route_Regex(
"p\/(a-zA-Z0-9)\.htm",
array(
'controller'=>'page',
'action'=>'index',
1=>'ja.htm'
),
array( 1 => 'page_name')
);
$route2 = new Zend_Controller_Router_Route_Regex("(a-zA-Z0-9)\.html",
array('controller'=>'page',
'action'=>'index',
1=>'ja.html'),
array(1=>'page_name'));
$redirect->addRoute('pages',$router);
$redirect->addRoute('hmtmled',$route2);
$front->setRouter($redirect);
}
I tried to enter url like: p/ja.htm but i get error: Invalid controller specified (p). I know its for reason of default route, but how to change that?
Is that method part of your Bootstrap class? If so, are you sure it is being run? Remember, the Bootstrap methods that get called automatically are those of the form _initXXX() (note the leading underscore).
Also, as #Tim Fountain astutely notes in the comments, the regex needs to be:
p/([0-9A-Za-z]+)\.htm
you try to remove the default routes:
//excerpt from ZF reference 24.5.4. Default Routes... If you do
not want this particular default route in your routing schema, you may
override it by creating your own 'default' route (i.e., storing it
under the name of 'default') or removing it altogether by using
removeDefaultRoutes():
// Remove any default routes
$router->removeDefaultRoutes();