Rendering a partial view in Zend for adding html to routing action layout - model-view-controller

I am rendering a page with a lot of frames (XHR contentpanes via dojo). This is done through a request to IndexController which sets up regions 'header,left,right,center,footer' with the exception, that center is not filled in with contents. This in turn is set by calling PaneController in menu.onclick. Caveat; search engines indexing service does not get center region contents.. I wish to bypass AJAX loading of center, if user enters via /index/index.
Relevant snippets from IndexController:
class IndexController extends Zend_Controller_Action {
public function indexAction() {
$this->indexModel = $this->view->indexModel = new Application_Model_Index();
// Goal is to render "/pane/main/" action and capture the HTML
$this->view->mainPane = (string) $this->renderPaneMain();
return $this->render();
}
public function renderPaneMain() {
// ActionStack ?
// action() ?
return $HTML;
}
}
Relevant stuff in Pane
class PaneController extends Zend_Controller_Action {
public function preDispatch() {
// will only return a contentpane, dont render layout
if ($this->getRequest()->isXmlHttpRequest()) {
$this->_helper->layout()->disableLayout();
$this->view->doLayout = true;
}
}
public function mainAction() {
this.render("main.phtml");
}
public function init() {
$this->panesModel = new Application_Model_Panes();
$variant = $this->getRequest()->getParam('variant', '');
// routing variables need to be set, how?
if (empty($variant))
$this->_redirect('/');
}
}
Basically, i need the PaneController to _not render the global layout but call its .phtml view file, once it has been setup with relevant model entries and such.
Any ideas as to how I can achieve this in its most efficient form?

Very well, ill attach the workaround im using here
The forms and the fork-logic i have moved to the model that is coexisting with PanesController. For the IndexController, which will present the default Pane as inline HTML without AJAX - there is a couple of duplicated initializations going on.
So, IndexModel extends the PanesModel - without initializing it. In my index.phtml view (for Index action) i have following code to render the inline html from a pane.
in index controller
$this->view->model = new IndexModel(); // extends PanesModel
$this->view->model->setDefaultProperties($variant, $pagination, ...);
in index view:
$this->partial("panes/main/main.phtml", array("model", $this->model);
and from pane view:
<?php if($this->model->goThisDirection()): ?>
Switch 1 HTML contents
<?php endif; ?>
Caveat: I also had to not render any form of layout within the pane (dojox contentpanes allows for <script> and <style> tags) - and this ofc ripples to any other pane action of mine.

Related

Livewire data tables can't access public property

I'm working with Livewire Datatables (https://github.com/mediconesystems/livewire-datatables)
In my component, I have:
<?php
namespace App\Http\Livewire;
use App\Job;
use Mediconesystems\LivewireDatatables\Http\Livewire\LivewireDatatable;
use Mediconesystems\LivewireDatatables\Column;
use Mediconesystems\LivewireDatatables\NumberColumn;
use Mediconesystems\LivewireDatatables\DateColumn;
class JobsTable extends LivewireDatatable
{
public $model = Job::class;
public function columns()
{
return [
Column::checkbox(),
NumberColumn::name('id')->label('ID')
->linkTo('cl/jobs/edit'),
Column::name('Entry_id')->label('Entry ID')
->defaultSort('asc')->filterable(),
Column::name('state')
->label('State')->filterable(),
Column::name('title')
->label('Title'),
Column::name('description')
->label('Description')->truncate(),
];
}
public function render()
{
return view('livewire.jobs-table');
}
public function store()
{
}
}
In my routing, I'm calling this as a full page component:
Route::get('/cl/jobs', JobsTable::class);
Everything is there, but the component doesn't actually render. It only renders the default content from app.blade.php.
If I add the {{slot}} variable to my jobs-table blade file, I get an saying it does not exist. I can see in the debug bar that component is loading, but not rendering to the page.
Updated
Based on feedback, I tried getting it to render to a custom slot:
''' return view('livewire.jobs-table')->layout('livewire.jobs-table')->slot('JobsTable');
'''
Then in the blade file:
{{ $JobsTable }}
</main>
I still get an error, telling me that $JobsTable is not defined.
]1
Any suggestions as to what I'm doing wrong?
It sounds that you have a seperate löayout for this component. Take a look what layouts you have. and then try to assign the layout with ->layout('layouts.job-layout');in your render funktion.
public function render()
{
return view('livewire.jobs-table')->layout('layouts.job-layout');
}

CodeIgniter Dry Navigation

My boss told me make dry navigation dont use repetitive code, for navigation i am trying to extend CI_Controler and with construct load header nav, body, footer files.
My question is when i create new controller and when i try to load different view files, how to achive that???
my extended controler
class MY_Controller extends CI_Controller
{
public function __construct() {
parent::__construct();
$this->load->view('view_header');
$this->load->view('includes/nav_home');
$this->load->view('view_home');
$this->load->view('view_footer');
}
}
and later when i am creating new controler how to load diffrent view files
class Pages extends MY_Controller
{
public function __construct() {
$this->load->view('includes/nav_new_view');
$
}
}
You can create a template library yourself. For example :
function template($view_name,$view_data){
//below will return html string from view name
$data['content'] = $this->load->view($view_name,$view_data,true)
//load main template view and pass the html string to main template
$this->load->view('main_template',$data);
}
In main template, just echo $content
If I understand your question, you're trying to achieve a template situation. For this, the best way is to actually call your templates view files within a primary page view. What I mean is your controller function (not the constructor, an actual class function representing a page) should call a primary view such as
$this->load->view('page1', $this->data);
and within that file, you call
$this->load->view('nav', $this->data);
then your content and then
$this->load->view('footer', $this->data);
You would then repeat the process for page 2 where in your controller's page2 function, you would call
$this->load->view('page2', $this->data);
and your page2 view file is almost identical to page1 except you use your page 2 content in that area.
You could even use a single template view file and pass it a $content variable (which obviously changes per page) and call
$this->load->view('template', $this->data);

zend 2: Automatically inject a template for all actions of a module without modifying site wide configuration

I am using the Zend skeleton application.
I want to have a sub menu bar (via a template) injected underneath the default site wide menu bar, but I don't want to modify the site wide app settings, I'd like to just have it in the module.
Looking at examples it seems I would have to manually inject the menu bar template in each of my controller's actions and in every template where I want it to appear like this:
public function indexAction() {
$view = new ViewModel();
$subNavView = new ViewModel();
$subNavView->setTemplate('helpdesk/helpdesk/subNav');
$view->addChild($subNavView, 'subNav');
return $view;
}
public function someAction() {
$view = new ViewModel();
$subNavView = new ViewModel();
$subNavView->setTemplate('helpdesk/helpdesk/subNav');
$view->addChild($subNavView, 'subNav');
....do something add variables to $view....
return $view;
}
public function someOtherAction() {
$view = new ViewModel();
$subNavView = new ViewModel();
$subNavView->setTemplate('helpdesk/helpdesk/subNav');
$view->addChild($subNavView, 'subNav');
....do something add variables to $view....
return $view;
}
...etc
And the "echo $this->subNav" in every template.
Is this the right way to do this or is there a way to have my module automatically include this template for every page (without modifying anything outside of the individual module)?
I read the docs, but I'm still confused on how to achieve this or if this is even possible.
If you want to update the view model directly, you could also do that in onBootstratp of your Module class:
public function onBootstrap($e) {
$view = $e->getApplication()->getMvcEvent()->getViewModel();
$subNavView = new ViewModel();
$subNavView->setTemplate('helpdesk/helpdesk/subNav');
$view->addChild($subNavView, 'subNav');
}
And of course you already have something like this in your layout:
<?php echo $this->subNav; ?>
You could also consider using the standard partial view helper and setting the template path as a variable in your model from your Module.php like this:
public function onBootstrap($e) {
$viewModel = $e->getApplication()->getMvcEvent()->getViewModel();
$viewModel->subNav = 'application/navigation/subNav.phtml';
}
Then you modify your /module/Application/view/layout/layout.phtml something like this
<?php if ($this->subNav) {
echo $this->partial($this->subNav);
} ?>
The drawback to this idea is that then you have a view model variable which will show up in all your models. This can be annoying, for example, in json results.
Last idea, you might want to consider a navigation view helper. You could implement https://github.com/spiffyjr/spiffy-navigation if you don't want to build one from scratch.
If you solve it with a view helper, either custom or pre-existing package such as Spiffy Jr's, then you'd modify your layout so it uses the helper something like this, and all the logic is provided by the helper class:
<?php echo $this->navigationMenu(); ?>
All three ideas will unclutter your controllers and let your Module set up the subNav in a way that is relevant to it, such as which routes it is valid for, etc.

How to display view without template?

I have view (frontend) in my own component (view.html.php):
class MevViewMev extends JView{
function display($tpl = null){
parent::display($tpl);
}
}
And template:
<?php defined('_JEXEC') or die('Restricted access'); ?>
<div>
ASFADSFDSF
</div>
How to display it without joomla template (head section, styles, etc). I want to call this part of jquery onclick method in the window.
To display the component only add "tmpl=component" parameter to url.
If need to display something besides component's view it can be customized - create "component.php" file in template's root folder and include in it whatever you need.
More templates can be done in the same way - create "some_template.php" in template's root folder and add "tmpl=some_template" parameter to url.
Start Edit
OK so the below works, but I found a better way. In your controller do ...
if (JRequest::getVar('format') != 'raw') {
$url = JURI::current() . '?' . $_SERVER['QUERY_STRING'] . '&format=raw';
header('Location: ' . $url);
// or, if you want Content-type of text/html just use ...
// redirect($url);
}
End Edit
You can set 'tmpl' to 'component', as suggested by Babur Usenakunov, in which case scripts and css may be loaded, like ...
JRequest::setVar('tmpl','component');
However if you want to create raw output you can add &format=raw or in your component make a view of type 'raw' ...
Unfortunately the only functional way I can find to make a viewType of raw render correctly is to call exit() after the view class calls parent::display() ...
In your controller.php ...
class com_whateverController() extends JController
{
function __construct()
{
// the following is not required if you call exit() in your view class (see below) ...
JRequest::setVar('format','raw');
JFactory::$document = null;
JFactory::getDocument();
// or
//JFactory::$document = JDocument::getInstance('raw');
parent::__construct();
}
function display()
{
$view = $this->getView('whatever', 'raw');
$view->display();
}
}
then in views/whatever/view.raw.php ...
class com_whateverViewWhatever extends JView
{
public function display($tpl = null)
{
parent::display();
exit; // <- if you dont have this then the output is captured in and output buffer and then lost in the rendering
}
}
I know this comes in very late, but for future readers, here's how I did it for my extension, without editing the template, or adding anything in the URL (since I have control over neither of those):
jimport('joomla.application.component.view');
use \Joomla\CMS\Factory;
// Comp stands for the Component's name and NoTmpl stands for the View's name.
class CompViewNoTmpl extends \Joomla\CMS\MVC\View\HtmlView {
// Force this view to be component-only
public function __construct() {
$app = Factory::getApplication();
$app->input->set('tmpl', 'component');
parent::__construct();
}

add iframe while calling controller to view in codeigniter

call controller to view i use this code..
i want to add "template/home/home" page in to iframe tag while calling controller to view.
how can i do?
class main_con extends Controller
{
function main_con()
{
parent::Controller();
// $this->freakauth_light->check('user');
$this->_container = $this->config->item('FAL_template_dir') . 'template/container';
$this->load->library('FAL_front', 'fal_front');
}
function index()
{
$data['redirect_page'] = 'template/home/home';
$this->load->vars($data);
$this->load->view($this->_container);
}
}
thank you in advance...
I'm not quite sure if I understand your problem but:
The iframe is in your view template right? So what you need to do is just print the content of your variable in the src attrib of the iframe.

Resources