For some pages of my application, I would like to use dvuhkolonchaty template. For this I would like to just use a different layout.
In the new layout except the variable $content, which displays the contents of a particular view, I would like to withdraw more other data in another column. Here is the code of the new layout:
<?php /* #var $this AdminController */ ?>
<?php $this->beginContent('/layouts/main'); ?>
<div class="container-fluid">
<div class="row-fluid">
<div class="span4">
<!-- Any data -->
</div>
<div class="span8">
<?php echo $content; ?>
</div>
</div>
</div>
<?php $this->endContent(); ?>
And that's just where Any data, I would like to display a different not template information (eg, shape or edit the list of properties is constantly changing depending on the viewing record ID).
Q How can I print information in the Any data?
All your controllers will extends Controller class;
In the Controller class, you make a property like this:
public $anyData = null;
In your any actions, you can set `$this->anyData = "anything";
then in your layout, you can write :
<div class="span4">
<!-- Any data -->
<?php
if($this->anyData!=null) {
//Process $this->anyData here, echo or do something you like;
}
?>
</div>
Related
I am trying to add an if else statement to a file in Magento.
Basically I want it to display different content depending on the body class.
For example, if the body element had a specific class, such as in:
<body class="specific-class">
Then within that body block, then the contents of it might display:
<section class="banner banner-inner <?php Mage::helper('function')->convert_category_name($category_name); ?>">
<div class="wrapper">
<?php echo $this->getChildHtml('breadcrumbs') ?>
<?php echo $this->getLayout()->getBlock('breadcrumbs')->toHtml(); ?>
</div>
<div class="bottom-rip"></div>
</section>
But if the body had a different class, or no class at all, it would default to:
<div class="no_content">
<?php echo="<h1>No content</h1>"; ?>
</div>
Does anyone know the syntax for performing such an operation?
I'm writing a CodeIgniter 3 application. My goal is to have a view, which is constantly (as the code goes along) flushed with the output content. I read some answers in stackoverflow, but I am not sure, how to do this.
I have a Controller wich renders the view, in the update method.
<?php
defined('BASEPATH') OR exit('No direct script access allowed!');
class Dataupdate extends MY_Controller {
function __construct() {
parent::__construct();
}
public function index() {
$this->render('dataupdate_list_view');
}
public function update() {
$this->render('dataupdate_update_view');
}
}
?>
Here is the class "MY_Controller".
<?php
defined('BASEPATH') OR exit('No direct script access allowed!');
class MY_Controller extends CI_Controller {
protected $data = array();
function __construct() {
parent::__construct();
$this->data['page_title'] = 'Team Portal';
$this->data['before_head'] = '';
$this->data['before_body'] = '';
}
/**
* Render method is used to render a view using a template.
* The given template delivers the HTML header and footer.
* The view contains the actual page content.
*
* #param string $the_view The view to be rendered
* #param string $template The template to render the view
*/
protected function render($the_view = NULL, $template = 'master') {
if ($template == 'json' || $this->input->is_ajax_request()) {
header('Content-Type: application/json');
echo json_encode($this->data);
} else {
// Get current user from database
$this->load->model('user_model');
$user = $this->user_model->get_record_by_name($_SERVER['REMOTE_USER']);
// Data to pass to view
$this->data['the_view_content'] = (is_null($the_view)) ? '' : $this->load->view($the_view, $this->data, TRUE);
$this->data['user'] = $user;
// Load view with data
$this->load->view('templates/' . $template . '_view', $this->data);
}
}
}
?>
Then I have a view, which outputs the content.
<div>
<!-- PAGE TITLE -->
<div class="page-title">
<h3>Daten Update</h3>
<div class="title_right">
</div>
</div>
<div class="clearfix"></div>
<!-- ALERTS -->
<div class="row">
<div class="col-md-12 col-sm-12 col-xs-12">
<div class="x_panel">
<div class="x_title">
<h2>Fehler<small>Kleiner Text</small></h2>
<div class="clearfix"></div>
</div>
<div class="x_content bs-example-popovers">
<div class="alert alert-danger alert-dismissible fade in" role="alert">
<strong>Strong text.</strong>What to do now?
</div>
</div>
</div>
</div>
</div>
<!-- CONTENT -->
<div class="row">
<div class="col-md-12 col-sm-12 col-xs-12">
<div class="x_panel">
<div class="x_title">
<h2>Neues Daten Update ausführen</h2>
<div class="clearfix"></div>
</div>
<div class="x_content">
<?php echo form_open('dataupdate/update'); ?>
<input type="text" name="test" />
<button>Ausführen</button>
<?php echo form_close(); ?>
</div>
</div>
</div>
</div>
</div>
This works fine. So far.
Now, what I try to achieve is the following:
I click on the "Ausführen" (Execute) button, which submits the form to the same url as this page
Then I want a php script to execute, which continously outputs content to the page. Not all content at once, but adds output after output to the page.
I hope I made myself clear.
Any suggestions or tutorials, on how to do that?
You'll need to force the output by calling ->_display method on the output class
For example for JSON output you'll do something like this:
$response = array('status' => 'OK');
$this->output
->set_status_header(200)
->set_content_type('application/json', 'utf-8')
->set_output(json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES))
->_display();
exit;
Same thing goes when you load a view, if you're 100% sure you won't need anything else, You may call _display manually to get the output; just be sure to call exit after that otherwise you'll end-up with a duplicated output (one from your manual call & the other from the automatic call).
Have a look at the user's guide for output class: http://www.codeigniter.com/user_guide/libraries/output.html
I've created a Joomla template (3.2). and my each page type has different class like, All article pages have article class, and contact us page have contact-us class
<!--For About us page -->
<div class='container article'>
...
</div>
<!--For Contact us page -->
<div class='container contact-us'>
...
</div>
and so on.. so is there any way to get this thing done ?
I am not preferring to create a template for each page..
You could get part of the url and if it contains some specific words, you can make an if () else (if ()else()) printing those divs or a case if you want more options
If you want to specifically identify a page type, you'll need to know the component and the view being displayed. If you're in the template file, you can get these like this:
$input = JFactory::getApplication()->input;
$component = $input->get('option');
$view = $input->get('view');
These are just strings so using them as a class is as simple as something like this:
<div class="container <?php echo $component, '-', $view; ?>" >...</div>
Which should give you something like this:
<div class="container com_content-article" >...</div>
When the page is an article view of the com_content component.
First set class name in one variable using different condition and then append this value in class attribute. like following:
<?php
$input = JFactory::getApplication()->input;
$view = $input->get('view');
$container_class=$view;
// also add more condition and set $container_class
?>
<!--For About us page -->
<div class='container <?php echo $container_class; ?>'>
...
</div>
I have a main view with a menu which helps me display another view. It's similar to this:
<div id="page">
<div id="menu">
Page1
Page2
</div>
<div id="content">
<!-- Page1 or Page2 are displayed here -->
</div>
</div>
I'm using php's Yii framework. Which makes me not to use <?php include("menuview.php"); ?>. So I'm looking for a different solution. I can do this with Ajax, but I would also like the link to change to mypage/controller/Page2. With Ajax I can only get it to this: mypage/controller/index#Page2
in main view, instead of include do
<?php echo $this->renderPartial('_page1', array('model'=>$model)); ?>
UPDATE:
protected/views/controller/page1.php and protected/views/controller/page2.php content at your liking
protected/views/layouts/custom.php:
<?php $this->beginContent('//layouts/main'); ?>
<div id="page">
<div id="menu">
<?php echo CHtml::ajaxLink('Page1', array('controller/page1'), array('update' => '#content')); ?>
<?php echo CHtml::ajaxLink('Page2', array('controller/page2'), array('update' => '#content')); ?>
</div>
<div id="content">
<?php echo $content; ?>
</div>
</div>
<?php $this->endContent(); ?>
protected/controllers/ControllerController.php:
class ControllerController extends Controller {
/**
* #var string the default layout for the views.
*/
public $layout = '//layouts/custom';
public function actionPage1() {
if (Yii::app()->request->isAjaxRequest)
$this->renderPartial('page1');
else
$this->render('page1');
}
public function actionPage2() {
if (Yii::app()->request->isAjaxRequest)
$this->renderPartial('page2');
else
$this->render('page2');
}
}
UPDATE2:
If you need the link in address bar to change too then your only option is to use regular link and not ajax <?php echo CHtml::link('Page1', array('controller/page1')); ?>
using ajax the preferred way is using hash like you mentioned.
how to create a widget out of an existing login action view ?
this is what I currently have in my login.php view file of the site's controller actinLogin()
<div id="login-wrapper">
<div class="login-container">
<?php $form=$this->beginWidget('CActiveForm', array('id'=>'login-form','enableAjaxValidation'=>true,)); ?>
<div class="login-input">
<p>
<?php echo $form->labelEx($model,'username'); ?>
<?php echo $form->textField($model,'username',array('placeholder'=>'username')); ?>
</p>
<p>
<?php echo $form->labelEx($model,'password'); ?>
<?php echo $form->passwordField($model,'password',array('placeholder'=>'password')); ?>
</p>
<div id="bmenu">
<ul class="menu">
<li class="register"><?php echo CHtml::link("Registration", array('wsmembers/register'));?></li>
<li class="login"><?php echo CHtml::submitButton('Login',array('id'=>'login_button')); ?></li>
</ul>
</div>
</div>
<?php $this->endWidget(); ?>
</div><!-- .login-container -->
<div class="login-bg-bottom"></div>
if I click the default login link from the navbar, that's the only time that code above shows
the login box at the upper right corner of the page
but the problem is, the login box should be at the homepage and must already be there
without clicking a login link at the navbar. so how am i gonna do that? this have something to do with main.php layout file right?
Indeed.
What you have defined is a view that is used for content. If you click the link the login action will be executed and it it will show the form.
If you want this to be shown always, just do a Yii::app()->controller->renderPartial on the view. Note that it cannot be $this->renderPartial as you would normally do since the main layout is not executed by the controller. I usually define an alias called "userViews" that points to protected/views so I can do:
Yii::app()->controller->renderPartial('userViews.site.login');
Or something like that. Hope that helps :)
As for the alias you can add this to your config:
Yii::setPathOfAlias('userViews', dirname(__FILE__) . '/../../protected/views');
This is assuming your views are indeed under protected views.