codeigniter can i stop loading header footer while displaying data in popup - php

I am displaying some data in popup but i don't want the header and footer there how can i achieve this in code-igniter
Note : i do not want to hide them by jQuery or CSS
This is my controller function to display data
function singleBookmarksView()
{
$web_url = $this->uri->segment(2);
$url_split_Array = explode('-', $web_url);
$web_id = $url_split_Array['0'];
//print_r($url_split_Array);
$data['singleBookmark'] = $this->bookmark_model->getSingleBookmark($web_id);
$data['bookmarkLabels'] = $this->getBookmarkLabel();
$this->load->view("header_view.php");
$this->load->view("bookmark_view.php", $data);
$this->load->view("footer_view.php");
}
Thanks

To do this you could either
function singleBookmarksView()
{
$web_url = $this->uri->segment(2);
$url_split_Array = explode('-', $web_url);
$web_id = $url_split_Array['0'];
$data['singleBookmark'] = $this->bookmark_model->getSingleBookmark($web_id);
$data['bookmarkLabels'] = $this->getBookmarkLabel();
$this->load->view("header_view.php");
$this->load->view("bookmark_view.php", $data);
$this->load->view("footer_view.php");
}
//create a new route for this
function singleBookmarksViewPopup()
{
$web_url = $this->uri->segment(2);
$url_split_Array = explode('-', $web_url);
$web_id = $url_split_Array['0'];
$data['singleBookmark'] = $this->bookmark_model->getSingleBookmark($web_id);
$data['bookmarkLabels'] = $this->getBookmarkLabel();
$this->load->view("bookmark_view.php", $data);
}
Or
//with this method add an extra value to the URI and it
//will show without the header and footer
function singleBookmarksView($popup = null)
{
$web_url = $this->uri->segment(2);
$url_split_Array = explode('-', $web_url);
$web_id = $url_split_Array['0'];
$data['singleBookmark'] = $this->bookmark_model->getSingleBookmark($web_id);
$data['bookmarkLabels'] = $this->getBookmarkLabel();
if (!$popup) {
$this->load->view("header_view.php");
}
$this->load->view("bookmark_view.php", $data);
if (!$popup) {
$this->load->view("footer_view.php");
}
}

Related

how to get return value in true condition

I have a controller code like this, but I don't know how to pass the variable in $date="dataInputan ['date']" into the ViewSewing function of the code section: $ date = ........;
i try using return,,
but the this code can't get true condition if
full code
public function index2()
{
if (isset($_POST['dataInputan'])) {
$dataInputan = $_POST['dataInputan'];
$date = $dataInputan['date'];
$rst = $this->dataLineSewingModel->getSewingLine($date);
echo json_encode($rst);
//$this->session->set_flashdata('dateset', $date);
return $date;
} else {
return date('Y-m-d');
}
}
public function viewSewing($GroupID)
{
//$date = $this->session->flashdata('dataset');
$date = $this->index2();
print_r($date);
$data['getGroup'] = $this->dataLineSewingModel->getDetailLineSewing($GroupID, $date);
$data['getTitle'] = $this->dataLineSewingModel->getTitleSewing($GroupID);
$data['GroupID'] = $GroupID;
$this->load->view('total_emp/lineSewingView', $data);
}
please help me
I assume that you want to call controller viewSewing from page viewSewing but you want the data from index2.
I think you can do something like this.
public function index2($dataIn)
{
if (isset($dataIn)) {
$dataInputan = $_POST['dataInputan'];
$date = $dataInputan['date'];
$this->dateAll = $dataInputan['date'];
$rst = $this->dataLineSewingModel->getSewingLine($this->dateAll);
echo json_encode($rst);
}
}
public function ViewSewing($GroupID)
{
$dataInput = $this->input->post('dataInputan');
$date = $dataInput['date'];
$this->index2($dataInput);
$data['getGroup'] = $this->dataLineSewingModel->getDetailLineSewing($GroupID, $date);
$data['getTitle'] = $this->dataLineSewingModel->getTitleSewing($GroupID);
$data['GroupID'] = $GroupID;
$this->load->view('total_emp/lineSewingView', $data);
}
public function ViewSewing($GroupID)
{
if (isset($_POST['dataInputan'])) {
//$_POST['dataInputan'] -> is array
$dataInputan = $_POST['dataInputan'];
$dateAll = $dataInputan['date'];
$rst = $this->dataLineSewingModel->getSewingLine($dateAll);
$json_data = json_encode($rst);
}
if($json_data!=''){
$data['json'] = $json_data;
}
$data['getGroup'] = $this->dataLineSewingModel->getDetailLineSewing($GroupID, $date);
$data['getTitle'] = $this->dataLineSewingModel->getTitleSewing($GroupID);
$data['GroupID'] = $GroupID;
$this->load->view('total_emp/lineSewingView', $data);
}
//this extract the json_data and show in view page
$result = json_decode($json, true));

Codeigniter prevent repeat data

I have a controller with 2 functions:
images
videos
I have created a header and footer template to load with my views and I want to set the css stylesheet to the user preferred setting "light" or "dark". So for example the user sets their theme to be dark I want to update the header view with dark.css, but I am currently repeating my code and I want to prevent that. I am having to do this twice. Once for images:
public function images()
{
//is the user logged in? if not redirect to login page
if ( ! $this->my_auth->logged_in())
{
redirect('auth/login', 'refresh');
}
//set the view data
$data['title'] = 'Upload Images | My Idea Cloud';
$data['heading'] = 'Upload Images';
$data['attributes'] = array(
'class' => 'dropzone',
'id' => 'image-dropzone'
);
// get users style and set the correct style sheet
$user_data = $this->my_auth->user()->row();
if ($user_data->style == 'light')
{
$data['flat_css'] = 'flat-ui-light.css';
$data['navbar_class'] = 'navbar-default';
$data['footer_class'] = 'bottom-menu-default';
$data['custom_css'] = 'custom-light.css';
$data['dropzone_css'] = 'dropzone-light.css';
}
elseif ($user_data->style == 'dark')
{
$data['flat_css'] = 'flat-ui-dark.css';
$data['navbar_class'] = 'navbar-inverse';
$data['footer_class'] = 'bottom-menu-inverse';
$data['custom_css'] = 'custom-dark.css';
$data['dropzone_css'] = 'dropzone-dark.css';
}
else
{
$data['flat_css'] = 'flat-ui-dark.css';
$data['navbar_class'] = 'navbar-inverse';
$data['footer_class'] = 'bottom-menu-inverse';
$data['custom_css'] = 'custom-dark.css';
$data['dropzone_css'] = 'dropzone-dark.css';
}
//load the views
$this->load->view('templates/frontend/front_header', $data);
$this->load->view('templates/frontend/front_navbar');
$this->load->view('frontend/upload_images', $data);
$this->load->view('templates/frontend/front_footer', $data);
And once for the videos function
public function videos()
{
if ( ! $this->my_auth->logged_in())
{
redirect('auth/login', 'refresh');
}
$data['title'] = 'Upload Videos| My Idea Cloud';
$data['heading'] = 'Upload Videos';
$data['attributes'] = array(
'class' => 'dropzone',
'id' => 'video-dropzone'
);
// get users style and set the correct style sheet
$user_data = $this->my_auth->user()->row();
if ($user_data->style == 'light')
{
$data['flat_css'] = 'flat-ui-light.css';
$data['navbar_class'] = 'navbar-default';
$data['footer_class'] = 'bottom-menu-default';
$data['custom_css'] = 'custom-light.css';
$data['dropzone_css'] = 'dropzone-light.css';
}
elseif ($user_data->style == 'dark')
{
$data['flat_css'] = 'flat-ui-dark.css';
$data['navbar_class'] = 'navbar-inverse';
$data['footer_class'] = 'bottom-menu-inverse';
$data['custom_css'] = 'custom-dark.css';
$data['dropzone_css'] = 'dropzone-dark.css';
}
else
{
$data['flat_css'] = 'flat-ui-dark.css';
$data['navbar_class'] = 'navbar-inverse';
$data['footer_class'] = 'bottom-menu-inverse';
$data['custom_css'] = 'custom-dark.css';
$data['dropzone_css'] = 'dropzone-dark.css';
}
$this->load->view('templates/frontend/front_header', $data);
$this->load->view('templates/frontend/front_navbar');
$this->load->view('frontend/upload_videos', $data);
$this->load->view('templates/frontend/front_footer', $data);
There is more code so that is why I do not combine the two. I am only showing partial code.
Can someone guide me in the right direction on how I can consolidate my code?
There is no use of elseif block in your code, also if you pull out common data to be passed via data, this is one attempt of minimization i can think of.
To apply this, remove if, elseif and else blocks from your code and put,
if($user_data->style == 'light')
{
$intensity = 'light';
$default = 'default';
}
else
{
$intensity = 'dark';
$default = 'inverse';
}
$data['flat_css'] = "flat-ui-{$intensity}.css";
$data['navbar_class'] = "navbar-{$default}";
$data['footer_class'] = "bottom-menu-{$default}";
$data['custom_css'] = "custom-{$intensity}.css";
$data['dropzone_css'] = "dropzone-{$intensity}.css";
If you want to make it more universal, create a function in same controller as,
function apply(&$data,$style)
{
if($style == 'light')
{
$intensity = 'light';
$default = 'default';
}
else
{
$intensity = 'dark';
$default = 'inverse';
}
$data['flat_css'] = "flat-ui-{$intensity}.css";
$data['navbar_class'] = "navbar-{$default}";
$data['footer_class'] = "bottom-menu-{$default}";
$data['custom_css'] = "custom-{$intensity}.css";
$data['dropzone_css'] = "dropzone-{$intensity}.css";
}
and replace the first code block shown in my answer with, one single line
$this->apply($data,$user_data->style);
and you will get those five variables defined in $data

Prestrashop - how to add content for Tab in back-office

Hi i have an issue with prestashop module, I've just created module called TestModule and in install method I got following code:
public function install() {
$parent_tab = new Tab();
foreach (Language::getLanguages(true) as $lang) {
$parent_tab->name[$lang['id_lang']] = 'TestModule';
}
$parent_tab->class_name = 'TestModule';
$parent_tab->id_parent = 0;
#copy(_PS_MODULE_DIR_ . $this->name . '/logo.png', _PS_IMG_DIR_ . 't/TestModule.png');
$parent_tab->module = $this->name;
$parent_tab->add();
if (!parent::install()) {
return false;
}
return true;
}
And it created the Tab "TestModule", but when I'm clicking on it there is the information that "Controller not found". How can I set some content here?
See this bellow code , it will help you you made mistake
$langs = Language::getLanguages();
$id_lang = (int)Configuration::get('PS_LANG_DEFAULT');
$smarttab = new Tab();
$smarttab->class_name = "AdminSmartBlog";
$smarttab->module = "";
$smarttab->id_parent = 0;
foreach($langs as $l){
$smarttab->name[$l['id_lang']] = $this->l('Blog');
}
$smarttab->save();
$tab_id = $smarttab->id;
#copy(dirname(__FILE__)."/AdminSmartBlog.gif",_PS_ROOT_DIR_."/img/t/AdminSmartBlog.gif");

Pass MySQL Variable to Joomla Module instead of using default field for Twitter Search

It seems I've hit a wall here and could use some help
Would like to pass a MySql variable to a Joomla Module
Im using Yootheme's Widget-kit to display tweets from a search term. Works great and all but you need to enter the twitter search term in the Module back end.
Instead I would like to use a variable ( already used on the page) and pass that variable to the Twitter module so it can display the tweets I want
Here are some lines of PHP with the variable I'd like to use
$document->setTitle(JText::sprintf('COVERAGE_DATA_PLACE', $this->country->country_name, $this->city->city_name));
$text = JString::str_ireplace('%city_name%',$this->city->city_name,$text);
$this->setBreadcrumbs(array('country','city'));
Is there any way to take the "City" variable and send it to the 'word" field found in the twitter module?
Here is the Code for the twitter module
<?php
Class: TwitterWidgetkitHelper
Twitter helper class
*/
class TwitterWidgetkitHelper extends WidgetkitHelper {
/* type */
public $type;
/* options */
public $options;
/*
Function: Constructor
Class Constructor.
*/
public function __construct($widgetkit) {
parent::__construct($widgetkit);
// init vars
$this->type = strtolower(str_replace('WidgetkitHelper', '', get_class($this)));
$this->options = $this['system']->options;
// create cache
$cache = $this['path']->path('cache:');
if ($cache && !file_exists($cache.'/twitter')) {
mkdir($cache.'/twitter', 0777, true);
}
// register path
$this['path']->register(dirname(__FILE__), $this->type);
}
/*
Function: site
Site init actions
Returns:
Void
*/
public function site() {
// add translations
foreach (array('LESS_THAN_A_MINUTE_AGO', 'ABOUT_A_MINUTE_AGO', 'X_MINUTES_AGO', 'ABOUT_AN_HOUR_AGO', 'X_HOURS_AGO', 'ONE_DAY_AGO', 'X_DAYS_AGO') as $key) {
$translations[$key] = $this['system']->__($key);
}
// add stylesheets/javascripts
$this['asset']->addFile('css', 'twitter:styles/style.css');
$this['asset']->addFile('js', 'twitter:twitter.js');
$this['asset']->addString('js', sprintf('jQuery.trans.addDic(%s);', json_encode($translations)));
// rtl
if ($this['system']->options->get('direction') == 'rtl') {
$this['asset']->addFile('css', 'twitter:styles/rtl.css');
}
}
/*
Function: render
Render widget on site
Returns:
String
*/
public function render($options) {
if ($tweets = $this->_getTweets($options)) {
// get options
extract($options);
return $this['template']->render("twitter:styles/$style/template", compact('tweets', 'show_image', 'show_author', 'show_date', 'image_size'));
}
return 'No tweets found.';
}
/*
Function: _getURL
Create Twitter Query URL
Returns:
String
*/
protected function _getURL($options) {
// get options
extract($options);
// clean options
foreach (array('from_user', 'to_user', 'ref_user', 'word', 'nots', 'hashtag') as $var) {
$$var = preg_replace('/[##]/', '', preg_replace('/\s+/', ' ', trim($$var)));
}
// build query
$query = array();
if ($from_user) {
$query[] = 'from:'.str_replace(' ', ' OR from:', $from_user);
}
if ($to_user) {
$query[] = 'to:'.str_replace(' ', ' OR to:', $to_user);
}
if ($ref_user) {
$query[] = '#'.str_replace(' ', ' #', $ref_user);
}
if ($word) {
$query[] = $word;
}
if ($nots) {
$query[] = '-'.str_replace(' ', ' -', $nots);
}
if ($hashtag) {
$query[] = '#'.str_replace(' ', ' #', $hashtag);
}
$limit = min($limit ? intval($limit) : 5, 100);
// build timeline url
if ($from_user && !strpos($from_user, ' ') && count($query) == 1) {
$url = 'http://twitter.com/statuses/user_timeline/'.strtolower($from_user).'.json';
if ($limit > 15) {
$url .= '?count='.$limit;
}
return $url;
}
// build search url
if (count($query)) {
$url = 'http://search.twitter.com/search.json?q='.urlencode(implode(' ', $query));
if ($limit > 15) {
$url .= '&rpp='.$limit;
}
return $url;
}
return null;
}
/*
Function: _getTweets
Get Tweet Object Array
Returns:
Array
*/
protected function _getTweets($options) {
// init vars
$tweets = array();
// query twitter
if ($url = $this->_getURL($options)) {
if ($path = $this['path']->path('cache:twitter')) {
$file = rtrim($path, '/').sprintf('/twitter-%s.php', md5($url));
// is cached ?
if (file_exists($file)) {
$response = file_get_contents($file);
}
// refresh cache ?
if (!file_exists($file) || (time() - filemtime($file)) > 300) {
// send query
$request = $this['http']->get($url);
if (isset($request['status']['code']) && $request['status']['code'] == 200) {
$response = $request['body'];
file_put_contents($file, $response);
}
}
}
}
// create tweets
if (isset($response)) {
$response = json_decode($response, true);
if (is_array($response)) {
if (isset($response['results'])) {
foreach ($response['results'] as $res) {
$tweet = new WidgetkitTweet();
$tweet->user = $res['from_user'];
$tweet->name = $res['from_user'];
$tweet->image = $res['profile_image_url'];
$tweet->text = $res['text'];
$tweet->created_at = $res['created_at'];
$tweets[] = $tweet;
}
} else {
foreach ($response as $res) {
$tweet = new WidgetkitTweet();
$tweet->user = $res['user']['screen_name'];
$tweet->name = $res['user']['name'];
$tweet->image = $res['user']['profile_image_url'];
$tweet->text = $res['text'];
$tweet->created_at = $res['created_at'];
$tweets[] = $tweet;
}
}
}
}
return array_slice($tweets, 0, $options['limit'] ? intval($options['limit']) : 5);
}
}
class WidgetkitTweet {
public $user;
public $name;
public $image;
public $text;
public $created_at;
public function getLink() {
return 'http://twitter.com/'.$this->user;
}
public function getText() {
// format text
$text = preg_replace('#(https?://([-\w\.]+)+(/([\w/_\.]*(\?\S+)?(#\S+)?)?)?)#', '$1', $this->text);
$text = preg_replace('/#(\w+)/', '#$1', $text);
$text = preg_replace('/\s+#(\w+)/', ' #$1', $text);
return $text;
}
}
// bind events
$widgetkit = Widgetkit::getInstance();
$widgetkit['event']->bind('site', array($widgetkit['twitter'], 'site'));
I believe you can do what you want with this:
http://www.j-plant.com/joomla-extensions/free-extensions/26-module-plant.html
This plugin supports module parameters overriding. Use the next code
for overriding parameters:
[moduleplant id="77" <param_name_1>="<param_value_1>" <param_name_N>="<param_value_N>"]
replace and with the necessary parameter name and value.
You can override as many parameters as you want.
Available module parameters can be found in module XML manifest
file. A manifest file is usually located in the next path:
modules/<module_type>/<module_type>.xml

Sending two data arrays to view from controller in codeigniter

I want to send two data arrays from my controller to view how can I do it ?
Following is my controller code
class Home extends CI_Controller {
public function box() {
$url = $this->pageURL();
$id_from_url = explode('/', $url);
$id = $id_from_url[6];
$query = $this->db->get_where('mc_boxes', array('idmc_boxes' => $id));
$row = $query->row();
$rowcount = $query->num_rows();
if ($rowcount <= 0) {
echo 'ID not found';
} else {
$box_id = $row->idmc_boxes;
$customer_id = $row->customers_idcustomers;
$language_id = $row->languages_idlanguages;
$template_id = $this->getTemplateID($box_id);
$template_data = $this->getTemplateData($template_id);
$variables_data = $this->getVariables($customer_id, $language_id);
$title = $variables_data[0]['value'];
$this->load->view('template', $template_data);
}
}
}
In my template view when I echo $title it says it is undefined
how can I send the whole $variables_data array with $template_data array
Thanks :)
Instead of using each array ,all do set to one
Like that,giving important sections only
...................
$data['template_data'] = $this->getTemplateData($template_id);
$data['variables_data'] = $this->getVariables($customer_id, $language_id);
$data['title'] = $variables_data[0]['value'];
$this->load->view('template', $data);
you can take $template_data and $variables_data in view files
Generally you pass in data as:
$data['template_data'] = $template_data;
$data['title'] = $$title;
....
$this->load->view('template', $data);

Categories