I'm completely confused on how Phalcon PHP renders its views. I want to create a new page called "manager".
From my understanding by creating a controller I can link it to a view. I create a controller called ManagerController.php and then added a view in views/manager/index.volt.
I added a bit of text the volt file to check if it works. When I go to /manager/ nothing shows up.
Am I doing this correct or do I have to assign a view somewhere?
class ManagerController extends ControllerBase
{
public function initialize()
{
$this->tag->setTitle('Files/My Files');
parent::initialize();
}
}
The initialize function on a controller is an event ran after constructing the controller
In order to display view for that controller it is necessary to at least setup an index action
In your you are interested in rendering a route of /manager/ , this will correspond to indexAction
class ManagerController extends ControllerBase
{
public function initialize()
{
$this->tag->setTitle('Files/My Files');
parent::initialize();
}
public function indexAction()
{
// This will now render the view file located inside of
// /views/manager/index.volt
// It is recommended to follow the automatic rendering scheme
// but in case you wanted to render a different view, you can use:
$this->view->pick('manager/index');
// http://docs.phalconphp.com/en/latest/reference/views.html#picking-views
}
// If however, you are looking to render the route /manager/new/
// you will create a corresponding action on the controller with RouteNameAction:
public function newAction()
{
//Renders the route /manager/new
//Automatically picks the view /views/manager/new.volt
}
}
Related
I am using Codeigniter framework to develop a website. I am currently working on home.php view under the view folder. I need to use UserInfo() function which is inside one of the controllers. Any suggestion how to access that function?
class Welcome extends CI_Controller {
public function UserInfo(){
$this->load->model('model_user');
$data['title'] = 'Users';
$data['users'] = $this->model_user->getUser();
$this->load->view('template/users', $data);
}
}
You cant call controller method inside another controller. Its No Way to do it.
You have two way to resolve this issue
If you want to access the function which place inside the
controller, add that into an model. So by loading model you can call
it.
use redirect('welcome/UserInfo') if you just need to call the function
As You want to call controller function in other controller.In codeigniter App folder core folder exists you make a custom core controller and all other controllers extend with your custom controller
In your Custom Core controller
class CustomCore extends CI_Controller
{
/* ---YOUR FUNCTION IN CUSTOMCORE---- */
public function mycorefunc()
{
//Do something
}
}
and your all other controllers extend with custom core
class YourController extends Customcore
{
function controllerfunction()
{
$this->mycorefunc();// Call corefunction
}
}
I have a custom module with a controller action which performs a certain function,
class Company_CustomModule_ActionController extends Mage_Core_Controller_Front_Action
{
public function doAction()
{
// do something
}
}
I have another controller in the same module (lets say "test"). I would like to call an action within this "test" controller in the above mentioned controller and pass it a parameter like,
class Company_CustomModule_ActionController extends Mage_Core_Controller_Front_Action
{
public function doAction()
{
// do something
// call the index in the "Test" controller
Mage::app()->getFrontController()->getResponse($data)
->setRedirect(Mage::getUrl('company/test'))
->sendResponse();
}
}
My goal is to pass some data from the Action controller to the Test Controller and execute the index action in the Test Controller from within the Action Controller.
Note: in essence, I would like to pass on the POST data received by the Action Controller to the Test Controller.
How would I go about doing this? any guidance would he helpful.
I'm not overly familiar with Magento, but since it's built on the Zend Framework you should be able to use the forward helper and pass your data in the params parameter:
return $this->_forward('test', 'company', $module, $params);
I have a situation where I have a base controller (a base actions.php file) in Symfony 1.4. I want to create another controller, for the same module, that extends that base controller.
I need to extend that base controller because I want to customize the behavior of certain visitors, that are identified based on an ID in the URL.
Any hints?
Another controller class for the same module, I think it's impossible in symfony.
I guess the easiest solution for you is to create another method in the same class, and then invoque it from the base one.
By Example: actions.class.php:
public function executeBaseAction(sfWebRequest $request) {
.. if($user....) then return $this->executeCustomAction($request);
}
public function executeCustomAction(sfWebRequest $request) {
// $this->setTemplate('anotherTemplate?');
}
Actually you can add another controller class for the same module.
You could include several files in your action directory in this way:
In action1Action.class.php
class action1Action extends sfAction
{
public function execute($request) {
//Your code here
}
}
This will use template action1Success.php
In action2Action.class.php
class action2Action extends sfAction
{
public function execute($request) {
//Your code here
}
}
This will use template action2Success.php
I'm little bit new to Zend, I want to use a controller action through out the entire application automatically, I don't have a clear idea to how to use it, thought about init() method, action helpers, etc.
Then instead of simply creating controller action create controllerAction Helper . Here you can find more about it
http://framework.zend.com/manual/en/zend.controller.actionhelpers.html
My_Helper_Magic extends Zend_Controller_Action_Helper_Abstract
{
public function preDispach()
{
//code inside here will run for entire application automatically
}
}
In your bootstrap do
Zend_Controller_Action_HelperBroker::addHelper(new My_Helper_Magic());
In Response to comment .
It depends upon your 'code fragment' , If your code fragment does not required to know nothing about module , controller, action , base url then you can use Bootstrap init function
like
public function _initAlways()
{
//see how this function name is prefixed with _init hence it will be called by ZF //everytime. You can put your code fragment here
//If your code fragment depends upon some stuff like baseurl then do action controller
// registration here instead
Zend_Controller_Action_HelperBroker::addHelper(new My_Helper_Magic());
}
In Response To comment
You can save any instance of your object inside Zend_Registy and retrieve it whereever you like
Inside Bootstrap.php
public function _initSetup()
{
$object = new My_Custom_Object();
Zend_Registry::set('my_custom_object',$object);
}
Later in your view or controller do
$myObject = Zend_Registry::get('my_custom_object'); //to access it
Sorry if this seems incredibly simple. I am only new to Symfony.
I just want to have a template/view which "contains" other views. So, for the following example, imagine on my /dashboard/ it will show both "statistics" and "inbox". I want the code for each of these to be within separate actions/methods.
<?php
class dashboardActions extends sfActions
{
public function executeIndex(sfWebRequest $request) {
// Load statisticsSuccess
// Load inboxSuccess
// Render them both "within" index template
}
public function executeStatistics(sfWebRequest $request) {
// Render statisticsSuccess
}
public function executeInbox(sfWebRequest $request) {
// Render inboxSuccess
}
}
Thanks for any assistance you can provide!
Make "statistics" and "inbox" components. Be sure to reference the documentation of the version of Symfony you're using.