I want to have a login form when i click www.example.com/login with the help of action helper .
My controllers/helpers directory contain the file name
the class Login.php is
In my views/login/index.phtml i m calling it like this
<?= $this->loginForm; ?>
Login.php
<?
class Zend_Controller_Action_Helper_Login extends
Zend_Controller_Action_Helper_Abstract
{
function Login($a)
{
//Consists of form elements
}
}
?>
I get the following error ---------
"Helper "login" does not support overloading via direct()"
How to display the form and what is the error about ?
I was able to get it right this way .
http://geekabyte.blogspot.nl/2012/08/understanding-zend-frameworks-plugin.html
in the Bootstrap.php
public function _initLoader()
{
//For configuring Zend Application to be aware of the Controller Action Helper
Zend_Controller_Action_HelperBroker::addPath(APPLICATION_PATH .'/controllers/helpers');
}
The LoginController.php
class LoginController extends Zend_Controller_Action
{
public function init()
{
/* Initialize action controller here */
}
public function indexAction()
{
$this->_helper->login->scream();
}
}
In the controller/helpers/Login.php
class Zend_Controller_Action_Helper_Login extends Zend_Controller_Action_Helper_Abstract
{
Public function scream()
{
echo "Here please help!!!";
}
}
Related
Is it possible to access controller from action helper?
class Zend_Controller_Action_Helper_UserLimit extends Zend_Controller_Action_Helper_Abstract
{
public test()
{
$this->getController(); // get controller which initiated the helper
}
}
Yes, it is possible:
$controller = $this->getActionController();
i have problem in zend framework basic application that class is not found. please help
i have basic structure and added model/tables directory. After my login page is displayed when i submit it then following error occurs
Fatal error: Class 'Application_models_tables_User' not found in E:\zendu\Apache2\htdocs\login\application\controllers\AuthController.php on line 18
Authcontroller.php
class AuthController extends Zend_Controller_Action
{
public function init()
{
/* Initialize action controller here */
}
public function indexAction()
{
// action body
}
public function loginAction()
{
$data = new Application_models_tables_User();
}
models/tables/User.php
class Application_models_tables_User extends Zend_Db_Table
{
protected $_name = 'users';
}
in application.ini
appnamespace = "Application"
i am using zend studio so basic structure is automaticaly created. so i have not to set include path of models.
Have a read through this :
The module resource autoloader sets the folder 'models' to the namespace Model.
I would change your class name to Application_Model_Table_User, and change your 'model/tables' folder to models/Table
In this example I want increase the session variable called "test" by one each time it enter to the controller. If comment the content of the method preDispath works fine but with this precise example, the session variable "test" increase in 3 or 5 each time.
I use Zend Framework 1.11.4
Why??? I hope you understand my question.
Remember this example is only to show the strange behavior of the method preDispatch
My plugin
class App_Plugins_Permisos extends Zend_Controller_Plugin_Abstract{
public function __construct(){}
public function preDispatch(Zend_Controller_Request_Abstract $request) {
$request->setModuleName('default');
$request->setControllerName('index');
$request->setActionName('index');
}
}
My bootstrap
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap{
protected function _initSession(){
Zend_Session::start();
}
protected function _initPlugins(){
$this->bootstrap('frontcontroller');
$this->frontController->registerPlugin(new App_Plugins_Permisos());
}
}
My Controller
class IndexController extends Zend_Controller_Action{
public function init(){}
public function indexAction(){
$s = new Zend_Session_Namespace('test');
if(isset($s->test)){
$s->test++;
}else{
$s->test = 1;
}
Zend_Debug::Dump($s->test);
die();
}
}
Thanks a lot
Try it putting in .ini resources.frontController.plugins.foo = "My_Plugin_Foo"
If works tell me! Tnks
I have two actions that are essentially identical, but need different URLs. Normally I would use _forward() to render the other action:
class MyController extends Zend_Controller_Action
{
public function actionOneAction()
{
$this->_forward('action-two');
}
public function actionTwoAction()
{
$this->view->foobar = 'foobar';
}
}
However, I have some code the is happening in preDispatch() that I only want to execute once:
class MyController extends Zend_Controller_Action
{
public function preDispatch()
{
//execute this only once before actionOne or actionTwo, but not both
}
public function actionOneAction()
{
$this->_forward('action-two'); //this won't work because preDispatch() will get called a second time
}
public function actionTwoAction()
{
$this->view->foobar = 'foobar';
}
}
So I thought maybe I could simply call the function directly, like this:
class MyController extends Zend_Controller_Action
{
public function preDispatch()
{
//execute this only once before actionOne or actionTwo, but not both
}
public function actionOneAction()
{
$this->actionTwoAction(); //execute the same code as actionTwoAction()
}
public function actionTwoAction()
{
$this->view->foobar = 'foobar';
}
}
But now Zend Framework is complaining about not being able to find the action-one.phtml view script. I don't want to render actionOne's view script. I want to render actionTwo's view script. What do I need to do?
Using render() seems to do the trick:
public function actionOneAction()
{
$this->actionTwoAction(); //execute the same code as actionTwoAction()
$this->render('action-two'); //renders the same view as actionTwoAction()
}
Yall:
I have a simple question, it might be a simple configuration issue, but
I have a Model defined, and when I try to access it from a controller it
fails.
The Model is in the model directory, and when I look at the quickstart app,
it seems like this should work.
Here is my model:
<?php
class Application_Model_User {
protected $_user;
protected $_password;
protected $_userId; // very simple right
}
?>
My controller just stops.. here is the controller code:
<?php
class UserController extends Zend_Controller_Action {
public function init() {
}
public function indexAction() {
// display login form
$users = new Application_Model_User();
echo "test never echos.. stopped above ? weird huh.."; // fails before ..
}
?>
Thank you everyone,
In application.ini
appnamespace = "Application_"
App structure:
/application/
/models/
/User.php
Class definition:
class Application_Model_User {}
Should work OK.