"Action" in indexController not rendering in view - php

I have an existing Zend 1.12 project with modules et al that I am trying to simply add a view to create another web page. So there is a controller called "Management" that has an index action, the default of course, and the correct view page called index.phtml. That is all fine and works inside the entire project/website.
class Management_IndexController extends Default_Controller_Action {
function indexAction() {
$this->view->headStyle()->appendFile('contact.css', 'contact')
->appendFile('message.css')
;
$this->setLayout('management');
$this->view->headTitle()->set('Management');
$message = new Com_Ui_Message();
$request = $this->_request;
$settings=new Com_Data();
$content=new Com_Data();
$data = new Com_Data($request->getPost());
$this->setFocus('#name');
}
function chatAction() {
$this->view->headStyle()->appendFile('contact.css', 'contact')
->appendFile('message.css')
;
$this->view->testMessage = "test";
}
}
So if I browse to http://www.bmcmusicgroup.com/management I see the default action public function, and that is all good. If I try to add another public function called chatAction inside of the management controller, and create a view page called chat.phtml in the appropriate folder where the index.phtml file is (the management index.phtml file), and then point my browser to http://www.bmcmusicgroup.com/management/chat I get nothing.
This is an existing site that I am trying decipher. Any pointers would be greatly appreciated.

Try changing your url to the following and you should see the page: http://www.bmcmusicgroup.com/management/index/chat. The URL you entered (http://www.bmcmusicgroup.com/management/chat) decomposes like so:
Module: management;
Controller: chat;
Action: index

Related

url redirect in mvc . i want to redirect localhost/windshield-replacement.html to localhost/greenvalleyaz

My applications is now in phalcon php framework. I want to redirect a url which contain .html at the end. To redirect, I wrote the controller name as WindshieldReplacementHtmlController.php but because of the dot in between I could not redirect. How can I solve this?
Redirect from:
localhost/windshield-replacement.html
to
localhost/greenvalleyaz
When I type localhost/windshield-replacement-html its redirecting to the target but when i use localhost/windshield-replacement.html its not detecting the controller.
is it the correct way to do that ?
In MVC you should not show the View Directly
you have to access a controller action --> in action you have to render view
In the Example I want to show user/order.phtml
I will access this page from Browser localhost/appname/user/orders
UserController.php
use Phalcon\Mvc\View;
class UserController {
function ProfileAction(){ //access localhost/appname/controller/profile
}
function loginAction(){ //access localhost/appname/controller/profile
}
function ordersAction(){ //access localhost/appname/controller/orders
$view = new View();
// Setting views directory
$view->setViewsDir('app/views/');
$view->start();
// Shows recent posts view (app/views/user/orders.phtml)
$view->render('user', 'orders');
$view->finish();
// Printing views output
echo $view->getContent();
}
}
Refer : Phalcon_Mvc_View

Map controller and view (Suit CRM 7.7.8)

I am very new to SugarCRM (SuitCRM 7.7.8). I could create a controller and could echo some strings in it. I wanted to make that value in a view file. I got confused whether I should use some js files or some tpl view file.
This is my code:
<?php
class MymoduleController extends SugarController {
//Can now put actions here
public function action_convert(){
echo "Hello world!";
//return true;
exit;
}
}
How can I map the controller to a view file.
In your controller action method add the following:
$this->view = 'EditView'
Change the 'EditView' to the view you wish to use. The built in MVC stuff is kept in include/MVC and the include/ListView, include/EditView, and include/MVC/DetailView.
If you take a look at say module/Accounts/views. You can see how views are implemented. It is best to create your code in the custom/modules/[module] folder. As this ensures that your changes will not be overwritten when you upgrade SuiteCRM.
You should separate your html with your view using tpls.
if you add the following in the display method of your view:
function display(){
$template = new Sugar_Smarty();
$template->assign('APP', $app_strings);
$template->assign('MOD', $mod_string);
echo $template->fetch('include/ListView/ListViewGeneric.tpl');
}
you can load your custom views.

how to call a view file from controller(cakePHP)

I am learning cakephp from few days ... so please help a bit thanks .
I made a controller --
class PostController extends AppController {
var $name='Posts';
function index(){
$posts=$this->Post->find('all');
$this->set(compact('posts'));
}
in view had post folder with index.ctp file . I want to ask from where it gets "CakePHP: the rapid development php framework" and from where it takes content . I send this data from controller so it prints only var_dump($posts); ... Thanks in advance.
cake php has default layout files in folder "app/view/Layout" .. file name default.ctp in this folder will be taken as default ..
if you open default.ctp in layout you will see something like
<h1><?php echo $this->Html->link($cakeDescription, 'http://cakephp.org'); ?></h1>
and other links defined ..you can comment the and check what changes you get in view.
here is from where view gets ""CakePHP: the rapid development php framework"
this line
<?php echo $this->fetch('content'); ?>
in layout fetch the data from controller to show in view which we set using $this->set() in controller
if you want to change the layout create your own in layout folder
and use in contoller like
class PostController extends AppController {
var $name='Posts';
function index(){
$posts=$this->Post->find('all');
$this->set(compact('posts'));
$this->layout = false; // ot you can set ypur own file like 'xyz' for 'xyz.ctp'
}
to set layout for each action in controller use
function beforeFilter() {
parent::beforeFilter();
$this->layout = 'layout';
}
To learn more about layout see http://book.cakephp.org/2.0/en/views.html#layouts
Hope you got me
"CakePHP: the rapid development php framework"
For above look inside views -> layout -> default.ctp file.
Also change default cakephp routing so you can see posts index action when you have posts in URL.
The best way to call a layout from controller is
$this->layout = 'Your layout page name';

How Silverstripe URLs work?

I am new to Silverstripe Framework / CMS. I see ./mysite/code/Page.php as controller and ./themes/simple/... as template directory. I logged into the admin panel and added new test page. The menu appears on the website with the URL http://example.com/test and content is displayed.
So what I want to know is, how to access the new controller let say Download.ss. I want to access the URL http://example.com/download/123/ without adding the new page download in admin panel. Thank you.
First of all, any files with a .ss extension are template files not controllers.
Create a new class in mysite/code/Download.php which extends Controller.
class Download extends Controller {
public function index() {
// Automatically handles URLs like http://example.com/Download
}
public function exampleaction() {
// Automatically handles URLs like http://example.com/Download/exampleaction
}
}
After that you'll want to add a new routes.yml file to the mysite/_config directory to specify that the index function on your new controller should handle calls to http://example.com/download/123.
---
Name: downloadrules
---
Director:
rules:
'download/$ID': Download
Now the '123' portion of your example URL will be accessible as $this->request->param('ID') within the index function.
Now you can do:
class Download extends Controller {
public function index() {
$fileID = $this->request->param('ID');
// Do your thing.
}
}
Documentation for this stuff is at http://doc.silverstripe.org/framework/en/reference/director

Zend Framework 2 display a view within a view

I have two modules Admin and Login.
I want to display the Login view 'login.phtml' within the admin view 'index.html'
I have the following in the Admin modules indexAction controller
public function indexAction()
{
$login = new LoginController();
$view = new ViewModel(array(
'theloginform' => $login->loginAction(),
));
return $view;
}
In the LoginAction method in the Login controller I return the ViewModel for the 'login.phtml' file.
public function LoginAction() {
$view = new ViewModel();
return $view;
}
The indexAction throws an error as the variable 'theloginform' is an object.
Catchable fatal error: Object of class Zend\View\Model\ViewModel could not be converted to string in...
If i add the following:
$authentication->loginAction()->captureTo('test')
The 'index.phtml' shows a string "content".
I have read that i may need to render the ViewModel before i assign it to the view variable 'theloginform', but i can't seem to get it to work, i have tried the following with no luck.
public function LoginAction() {
$view = new ViewModel();
$renderer = new PhpRenderer();
$resolver = new Resolver\AggregateResolver();
$map = new Resolver\TemplateMapResolver(array(
'login' => __DIR__ . '/../view/login.phtml'
));
$resolver->attach($map);
$view->setTemplate("login");
return $renderer->render($view);
}
If get the following error:
Zend\View\Renderer\PhpRenderer::render: Unable to render template "login"; resolver could not resolve to a file
I have even tried adding the DI into the autoload_classmap.php file but still get the same error, i have double checked the login.phtml file is at the correct path:
'/Login/view/login/login/login.phtml' I even copied it to '/Login/src/Login/view/login.phtml'
Very confused have read then re-read the Zend documentation, i just want to pass a view to another view...
If you need share some view content you can use partials for that:
$this->partial('partial/login.pthml', array()); //add this to your index view
you can read about them here
You may also find some usefull information: How does Zend Framework 2 render partials inside a module?
As per this zf2 documentaion page
Write this in login Action:
public function loginAction()
{
return new ViewModel();
}
And in indexAction :
$view = new ViewModel(
array(
//here any thig you want to assign to index view
)
);
$loginView = new ViewModel(
array(
//here any thig you want to assign to login view
)
);
$loginView->setTemplate('moduleName/controllerName/login');
$view->addChild($loginView, 'login');
return $view
In index.phtml you can just echo login <? echo $this->login ?> where ever you want to display loginView.
In ZF 1.x I would likely recommend you build an action helper that is referenced to a view placeholder or a controller plugin that calls back to loginAction for the form logic.
In Zf2 it looks like action helpers have been replaced by controller plugins and seem to be triggered through the event manager and may need to be aware of one or more of the "managers". However the placeholder view helper still exists and even seems somewhat familiar.
I would suggest you look into building/adapting a controller plugin for your login form display that can then be attached to a placeholder view helper. You might be able to get the required functionality with just a view helper, if you're lucky.
I wish I could help more, but I'm still wading through this mess myself.
Good luck.
In you admin view you have to use the render view helper and echo the script rendered, so you can do echo $this->render($this->theloginform);

Categories