session in codeigniter Undefined property: CI::$session - codeigniter

I'm having trouble loading my view on my login page . Having problems with the session here . I have a helper class that $ key security is part of it . But I think it is to do a session as an error saying .
I thought I had prepared a num lines was not sure whether also that it may cause.
<?php $this->load->library('session');
if(!$this->session->user_email)
{ ?>
<li <?php echo ($controller=="login" )? "class='active'": ""?>>
<a href="<?php echo base_url('login') ?>">
Login
</a>
</li>
<?php } else { ?>
<li>
<a href="<?php echo base_url('login/logout') ?>">
Logout
</a>
</li>
<?php } ?>
this problem
Error was encountered
Severity: Notice
Message: Undefined property: CI_Loader::$session
Filename: views/header.php
Line Number: 145
Backtrace:

go to autoload.php in config folder and
replage this
$autoload['libraries'] = array('session');
to
$autoload['libraries'] = array();

After reviewing you code, you should not do it in helper. You should do it in your View.php. In your View.php, should use $CI = & get_instance();.
$CI = & get_instance();
$CI->load->library('session'); //change from $this->load->library('session');
$CI->session->user_data('user_email'); // change from $this->session->user_email
Get the html code from view as a variable:
$html_code = $this->load->view('folder/view_name',$data,true);

Related

Stripe Cashier: Call to a member function subscribed() on null

I am building a Stripe subscription PHP website using Laravel I am getting this error when I am trying to check if user is subscribed.
The error is in the view Laravel says its on this line #if ($user->subscribed()).
My code:
#extends('temp.main')
#section('content')
#if ($user->subscribed())
<p>Subscribed</p>
#else
<p>Not Subscribed </p>
#endif
#stop
The error:
Call to a member function subscribed() on null
<?php $__env->startSection('content'); ?>
<?php if($user->subscribed()): ?>
<p>Subscribed</p>
<?php else: ?>
<p>Not Subscribed </p>
<?php endif; ?>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('temp.main', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>
You need to check Auth::check() before using Auth::user()
Something like this:
#if (Auth::check() && !$user->subscribed())

how to give link to each attributes of a manufacturer

I have added 4 to 5 attributes in manufacture and shown in right column of front end.Now i want to link the each attributes of manufacture. if i will click an attribute of a manufacturer, it will show all the products which contain that arribute/brand.
if anyone knows this, please help me out.
thanks!
I have shown the attribute name in front end by the below code
<?php
$attribute = Mage::getSingleton('eav/config')->getAttribute('catalog_product', 'Manufacturer');
if ($attribute->usesSource()) {
$options = $attribute->getSource()->getAllOptions(false);
if(count( $options)>0){
?>
<div class="title_box">Manufacturers</div>
<?php $i=1;?>
<ul class="left_menu">
<?php
foreach($options as $eachval){
?>
<?php if($i%2==0){ ?>
<li class="even"><?php echo $eachval['label']?></li>
<?php } else { ?>
<li class="odd"><?php echo $eachval['label']?></li>
<?php } $i++; ?>
<?php } ?>
</ul>
<?php } } ?>
I have made one page manu.phtml in catalog/product page and put the following above code now how to give link to that arribute...........please describe briefly
in href link,what i have to write so that when i will click on any attribute it will show all products associated to that attribute/brand.
There is always the option of creating a new module with a custom controller that would list the products from a specified brand, but that is a painful process even if it's the clean way.
Here is a simple version if you don't mind the ugly urls.
The main idea is to link your brand names to the advanced search page with a specific brand filled in.
You can get the url like this:
$url = Mage::getUrl('catalogsearch/advanced/result', array('_query'=>'brand='.$value->getId()))
You just need now to get the id of the specific brand ($value->getId()), but if you can get the name you can get the id also.
And don't forget to specify that the brand attribute is used in advanced search. You can do that by editing the attribute in the backend.
[EDIT]
Make your ul element look like this:
<ul class="left_menu">
<?php
foreach($options as $eachval){
$url = Mage::getUrl('catalogsearch/advanced/result', array('_query'=>'Manufacturer='.$eachval['value']));
?>
<?php if($i%2==0){ ?>
<li class="even"><?php echo $eachval['label']?></li>
<?php } else { ?>
<li class="odd"><?php echo $eachval['label']?></li>
<?php } $i++; ?>
<?php } ?>
</ul>
Small tip off topic. You can avoid duplication of the li elements in your code like this
<ul class="left_menu">
<?php
foreach($options as $eachval){
$url = Mage::getUrl('catalogsearch/advanced/result', array('_query'=>'Manufacturer='.$eachval['value']));
?>
<li class="<?php echo ($i%2 == 0) ? 'even':'odd';?>"><?php echo $eachval['label']?></li>
<?php } $i++; ?>
<?php } ?>
</ul>

sort collection of category by name

I have custom links in menu that shows categories in drop-down.
For that I made a file in catalog/navigation->mainmenu.phtml
(a custom file)
Now, I want to show categories after sorting it by name. please help me how can I sort collection of categories by name. I already set order of category in admin. But in front-end it show unsorted.
Code is:-
<?php $defaultcategory= Mage::app()->getStore()->getRootCategoryId();?>
<?php $mainchildren = Mage::getModel('catalog/category')->getCategories($defaultcategory);?>
<ul>
<?php foreach ($mainchildren as $subcategory) : ?> <?php // 2 level ?>
<?php if($subcategory->getIsActive()):?>
<li id="show_subcat" class="<?php if($i==1): echo 'first'; endif; ?>" >
<?php $childid=$subcategory->getId();?>
<?php $subchild = Mage::getModel('catalog/category')->getCategories($childid);?>
<?php foreach ($subchild as $subchildcategory) : ?>
<?php $path=$subchildcategory->getRequestPath()?>
<?php break;?>
<?php endforeach ?>
<a href="<?php echo $this->getUrl().$path; ?>">
<?php echo $name= $subcategory->getName().$subcategory->getEnable() ?>
</a>
</li>
<?php endif;?>
<?php endforeach; ?>
</ul>
You can try :
children = Mage::getModel('catalog/category')->getCategories($defaultcategory)
->addAttributeToSort('name', 'ASC');
or :
children = Mage::getModel('catalog/category')->getCategories($defaultcategory)
->setOrder('name','ASC);
$categories = Mage::helper('catalog/category');
$collection = $categories->getStoreCategories(false,true,false);
foreach($collection as $_category)
{
//Do something
echo $_category->getName();
}
use this code to get collection and follow this link for more detailIn magento - same code for getting all categories running well with sorted in localhost but not in web server

Displaying posts from specific categories with the AheadWorks blog extension for Magento

I'm using the AheadWorks blog extension for Magento, and my blog pages are working fine. But I want excerpts of my latest posts from certain categories to appear on my home page. I've successfully setup everything thus far by adding:
<block type="blog/blog" name="blog.latest" template="aw_blog/blog-home.phtml" />
to "layout.xml", by adding:
<?php echo $this->getChildHtml('blog.latest') ?>
to my home page's phtml file, and by creating "template/aw_blog/blog-home.phtml".
The problem is that I can't figure out how to limit what categories are shown. For example, you'll see in my "blog-home.phtml" file below that I'm trying to limit the posts to the "news" category. I've tried lots of solutions from other forums, but no matter what I do, I see posts from every category. Does anyone know what I need to add/take away from my code to limit the categories?
<?php $posts = $this->getPosts("news"); ?>
<div id="messages_product_view">
<?php Mage::app()->getLayout()->getMessagesBlock()->setMessages(Mage::getSingleton('customer/session')->getMessages(true)); ?>
<?php echo Mage::app()->getLayout()->getMessagesBlock()->getGroupedHtml(); ?>
</div>
<?php $numberOfPosts = 1 ?>
<?php $renderedPosts = 0 ?>
<?php foreach ($posts as $post): ?>
<div class="postWrapper">
<div class="postTitle">
<h2><a href="<?php echo $post->getAddress(); ?>" ><?php echo $post->getTitle(); ?></a></h2>
</div>
<div class="postContent"><?php echo $post->getPostContent(); ?></div>
<?php echo $this->getBookmarkHtml($post) ?>
<div class="tags"><?php echo $this->getTagsHtml($post) ?></div>
<div class="postDetails">
<?php if ($this->getCommentsEnabled()): ?>
<?php echo $post->getCommentCount(); ?> <a href="<?php echo $post->getAddress(); ?>#commentBox" >Comments</a> |
<?php endif; ?>
<?php $postCats = $post->getCats(); ?>
<?php echo "<h1>" . $postCats[2] . "</h1>"; ?>
<?php if (!empty($postCats)): ?>
<?php echo Mage::helper('blog')->__('Posted in'); ?>
<?php foreach ($postCats as $data): ?>
<?php echo $data['title']; ?>
<?php endforeach; ?>
<?php else: ?>
<?php endif; ?></div>
<?php $renderedPosts ++ ?>
<?php if ($renderedPosts = $numberOfPosts) {
break;
}
?>
</div>
<?php endforeach; ?>
<?php //$this->getPages(); ?>
Following is the quick solution:
Go to aw_blog frontend template, default might be this app/design/frontend/base/default/template/aw_blog/menu.phtml
check and replace:
if ($posts = $this->getRecent():
with
$currentBlogCat = Mage::getSingleton('blog/cat');
if ($posts = $this->getRecent($currentBlogCat['cat_id'])):
Now open up /app/code/community/AW/Blog/Block/Menu/Sidebar.php
check for the below function:
public function getRecent()
add a parameters to it:
public function getRecent($currentCat=false)
Also, replace the following code block
$collection = clone self::$_collection;
if (array_key_exists('categories',$data = $this->getData();) && count(explode(',', $data['categories'])) == 1) {
with
$collection = clone self::$_collection;
$data = $this->getData();
if($currentCat>0)$data['categories']=$currentCat;
# Category fix #
if (array_key_exists('categories',$data ) && count(explode(',', $data['categories'])) == 1) {
Thanks!

Grocery_Crud not visible. Need to understand how to set filer

I'm having trouble understanding how to place grocery_CRUD into a view.
My function in my control looks like this:
function folio()
{
$crud = new grocery_CRUD();
$crud->set_table('rfid');
$crud->columns('rfid','timestamp');
$data['output'] = $crud->render();
$data['title'] = 'Control Escolar - Folio';
$this->db->where('id', $this->uri->segment(3));
$data['query'] = $this->db->get('alumnos');
$this->load->view('folio_view', $data);
}
The code in my view file looks like this.
<?php foreach($query->result() as $row) { ?>
Datos Vitales - <B>Status:</b> <?=$row->status?><hr>
<B>Nombre:</b> <?=$row->nombre?> <B>Fecha de Nac:</B> <?=$row->fecha_nac?></br>
<B>Edad:</b> <?=$row->edad?> <B>Sexo:</B> <?=$row->sexo?> <B>Lugar de Nac:</B> <?=$row->lugar_nac?>
<B>Nacionalidad:</B> <?=$row->nacionalidad?><br><br>
Datos Escolar<hr>
<B>Folio:</b> <?=$row->folio?> <B>Grado:</b> <?=$row->grado?> <B>Grupo:</b> <?=$row->grupo?> <B>Turno:</b> <?=$row->turno?> <B>RFID:</b> <?=$row->rfid?><br><br>
Datos Generales<hr>
<B>Domicilio:</b> <?=$row->domicilio?> <B>Colonia:</b> <?=$row->colonia?> <B>Codigo Postal:</b> <?=$row->cpostal?></br>
<B>Telefono Particular:</b> <?=$row->telepart?> <B>Municipio:</b> <?=$row->municipio?></br>
<B>Telefono de Emergencia:</b> <?=$row->tele_emer?> <B>Tutor:</b> <?=$row->tutor?><br><br>
Datos Medicos<hr>
<B>Tipo de Sangre:</b> <?=$row->tipo_de_sangre?></br>
<B>Condiciones Conocidas:</b> <?=$row->condiciones?></br></br>
<hr>
<B>Entradas/Salidas Registradas:</b>
<?php echo $output; ?>
<?php } ?>
Which works well, however when I run it I get this where the CRUD should appear:
A PHP Error was encountered
Severity: 4096
Message: Object of class stdClass could not be converted to string
Filename: views/folio_view.php
Line Number: 65
What I'm trying to actually accomplish is for the CRUD to show the only the RFID entries matching the RFID field matching the student.
Actually the error describes exactly what is wrong there. So the problem is that you try to echo an object.
So imagine that your $output is an object like this:
stdClass Object
(
[output] => Your output will appear here....
[js_files] => Array
(
...
)
[css_files] => Array
(
...
)
)
So the solution to your problem is simply this:
echo $output->output;
Also consider that the only thing that grocery CRUD requires is to show somewhere the js_files and the css_files , so don't forget to have this in your template or view:
<?php foreach($output->css_files as $file): ?>
<link type="text/css" rel="stylesheet" href="<?php echo $file; ?>" />
<?php endforeach; ?>
<?php foreach($output->js_files as $file): ?>
<script src="<?php echo $file; ?>"></script>
<?php endforeach; ?>
If you want to be more "readable" to you can simply do this:
$data['gcrud'] = $crud->render();
And in your view/template to have something like this:
<?php foreach($gcrud->css_files as $file): ?>
<link type="text/css" rel="stylesheet" href="<?php echo $file; ?>" />
<?php endforeach; ?>
<?php foreach($gcrud->js_files as $file): ?>
<script src="<?php echo $file; ?>"></script>
<?php endforeach; ?>
...
<?php echo $gcrud->output; ?>
Lastly but not least, consider that the thing that you are trying to do will not work in the first place as I understood you want multiple CRUDs in one page:
<?php foreach($query->result() as $row) { ?>
...
<B>Entradas/Salidas Registradas:</b>
<?php echo $output->output; ?>
<?php } ?>
However you will realize that for the time being it will not work well for you as grocery CRUD doesn't support multiple CRUD forms in one page for the moment. So if you actually want to use grocery CRUD you have to change the logic that the view will show it

Resources