What I am trying to do is that, whenever the user clicks on a specific assignment, they will redirect to the detail page. The detail page will have different information according to what assignment they clicked on. However, I have no idea how to implement this feature.
My home function in Controller/project is as follows
public function home() {
/*if($this->input->cookie('login_status')=='0'){
header("location: Welcome/login");
} else{
*/
$this->load->database();
$this->load->model('scheduler_model');
$this->load->view('header.php');
$data['username'] = $this->input->cookie('username');
$data["getnames"]=$this->scheduler_model->get_users();
$this->load->view('home/homepage',$data);
$data["getassignments"]=$this->scheduler_model->get_assignment();
$data["getselectedcourses"]=$this->scheduler_model->get_select_course();
$this->load->view('home/assignments',$data);
//}
}
My assignment.php in view is as follows:
foreach($getassignments as $getassignment){
if(in_array($getassignment->courseID,$courseArray)){
if($getassignment->due>date("Y-m-d")){
?><a href="detail">
<?php
$assignName='assignment'.$i;
echo $getassignment->name," ",$getassignment->due;
//$this->input->set_cookie('assignName',$getassignment->name,time()+3600);
$assignList =array(
$assignName=>$this->input->set_cookie($assignName,$getassignment->name,time()+3600)
);
?></a>
<?php
echo "<br>";
$i=$i+1;
}
}
}?>
What I am trying to do is that, whenever the user clicks on a specific
assignment, they will redirect to the detail page. The detail page
will have different information according to what assignment they
clicked on. However, I have no idea how to implement this feature. My
home function in Controller/project is as follows
This is how it works!
You will have a method in a controller that list all assignments for your example
function home() {
$data["getassignments"]=$this->scheduler_model->get_assignment();
$this->load->view('home/homepage',$data);
}
You should have a view to listing all those assignments.
foreach($getassignments as $getassignment){
echo "<p><a href = 'controller/details/".$getassignment->id."'>".$getassignment->name."</p>"
}
you should have another method inside a controller to view that selected assignment
function detail($id){
$data["getassignment"]=$this->scheduler_model->get_assignment($id);
$this->load->view('details', $data);
}
Finally, you need a detail view to display the one you need for the selected assignment
Related
I am Trying To Reload Contents Of Page. Through link button Filter In PHP
By Passing Some Value Through Query String To Controller Method.
The Controller Method Loads The Same Page From Where I am Passing Query String.
But The View Is Not Reloading.
But If I Call The Controller Method Some Other View It Works Fine.
here is my code
mainview.php
English
maincontroller.php
Here Is The Index Method Of Controller.
$movielanguage=$this->input->get('language');
if(!empty($movielanguage))
{
$moviedata['popularmovies']=$this->main_model-
>getmoviebylanguage($movielanguage);
}
$moviedata['allmovies']=$this->main_model->getAllMovies();
$this->load->view('home/mainview.php',$moviedata);
}
Here View Does Not Refresh Its Contents
How Can I Solve This
Hope this will help you :
First if you want a single view ,should put you code it in if else condition and second assign your data in same variable
Your code should be like this :
public function index()
{
$movielanguage=$this->input->get('language');
if(! empty($movielanguage))
{
$moviedata['movies']=$this->main_model->getmoviebylanguage($movielanguage);
}
else
{
$moviedata['movies']=$this->main_model->getAllMovies();
}
$this->load->view('home/mainview.php',$moviedata);
}
Second : and if you want to add different view for different category of movies
You can do like this :
public function index()
{
$movielanguage=$this->input->get('language');
if(! empty($movielanguage))
{
$moviedata['popularmovies']=$this->main_model->getmoviebylanguage($movielanguage);
/*popularview is just an example*/
$this->load->view('home/popularview.php',$moviedata);
}
else
{
$moviedata['allmovies']=$this->main_model->getAllMovies();
/*allview is just an example*/
$this->load->view('home/allview.php',$moviedata);
}
}
I have set category page my default home page.But now i want to show CMS(Home page) for not logged in user while for logged-in i want to show category page.Means how i can set logic that can load both cms pages. How can i do that ? Thanks for any help in advance
<?php if(!Mage::getSingleton('customer/session')->isLoggedIn()): ?>
load->category page
<?php else: ?>//If user is NOT logged in
Load home page default one
<?php endif; ?>
IF you want only to check condition on home page .You can do like this .Change little bit code for CMS controller like this :
class Mage_Cms_IndexController extends Mage_Core_Controller_Front_Action
{
public function indexAction($coreRoute = null)
{
if(Mage::getSingleton('customer/session')->isLoggedIn())
{
Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getUrl('catalog/category/view/id/3'));
}else{
$pageId = Mage::getStoreConfig(Mage_Cms_Helper_Page::XML_PATH_HOME_PAGE);
if (!Mage::helper('cms/page')->renderPage($this, $pageId)) {
$this->_forward('defaultIndex');
}
}
}
Try and inform me about results.Hope this will solve your issue
This might work in your case :
// condition depending on login status of user
if(!$this->helper('customer')->isLoggedIn())
{
Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getBaseUrl());
die();
}
else
{
Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getUrl('YOUR_CATEGORY_URL'));
die();
}
IF above doesn't work, try this :
$sessionCustomer = Mage::getSingleton("customer/session");
if($sessionCustomer->isLoggedIn()) {
Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getUrl('YOUR_CATEGORY_URL'));
} else {
Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getBaseUrl());
}
I am a newbie to Codeigniter. As part of studying it, I created a form which inserts data to the database. After insertion it is not redirecting properly to the form view page (formvalidation.php).
Form Action
public function submitform()
{
$formdata['username']=$this->input->post('username');
$formdata['address']=$this->input->post('address');
$formdata['state']=$this->input->post('state');
$formdata['country']=$this->input->post('country');
$data['state']=$this->getstatearray();
$data['country']=$this->getcountries();
if($this->userprofile_model->setdata($formdata)=='success')
{
$this->load->view('formvalidation/formvalidation',$data);
}
else
{
$this->load->view('formvalidation/formvalidation',$data);
}
}
Form view page (formvalidation.php)
echo form_open('formvalidation/submitform');
echo form_input('username');
echo "<br>".form_textarea("address");
echo "<br>".form_dropdown('state',$state);
echo "<br>";
echo form_dropdown('country',$country);
echo "<br><br>".form_submit('submit','Submit');
echo form_close();
Model (userprofile_model.php)
class userprofile_model extends CI_Model {
public function __construct()
{
$this->load->database();
}
public function setdata($data)
{
$this->db->insert('userprofile',$data);
if($this->db->affected_rows()>0)
{
echo "success";
}
else
{
echo "fail";
}
}
}
Now the value is getting inserted into the database. But after insertion I want to redirect it to the url http://www.example.com/codeigniter/index.php/formvalidation/. But instead, it is now redirecting to http://www.example.com/codeigniter/index.php/formvalidation/submitform where submitform is the form action method.
How can I solve this problem? I tried with putting exit; after the page redirect function. But it won't work. Please help me to fix this.
Thanks in advance.
yes it will, because there is no redirect code. When the form is submitted your submitform function is executed and in that function you are loading the view. So if you want to redirect
to something else you must use the redirect() function.
public function submitform()
{
$formdata['username']=$this->input->post('username');
$formdata['address']=$this->input->post('address');
$formdata['state']=$this->input->post('state');
$formdata['country']=$this->input->post('country');
$data['state']=$this->getstatearray();
$data['country']=$this->getcountries();
if($this->userprofile_model->setdata($formdata)=='success'){
redirect("Your URL");
}
else{
redirect("Your URL");
}
}
Also you must properly sanitize the user input. You must validate your form inputs before passing it to model. You can find more info here
First Load the view page in controller index function.
function index()
{
$this->load->view('v_bank_master');
}
Then in model page, after insertion done. give the below code.
redirect('give your controller page name here','refresh');
Your page will now redirect to the view page after insertion.
Hope it will help you...
I use redirect('yourControllerName', 'refresh').
Read more here: Redirect()
After insertion give the below code
redirect('controller_name/function_name');
Maybe a simple question but how do I change my login box after logging in. Such as 'Welcome user'
I can't find good examples ...
My code looks like this
users_controller
function login {
}.. with login element
See here as example: http://groups.google.com/group/cake-php/browse_thread/thread/56ff0ce37fb06a30
You have 2 options:
Depending of your login state, choose another element, like:
function login() {
if ($isUserLoggedIn == false) {
// render login element
} else {
// render welcome element
}
}
this is more bad option In login element add logic like:
if (!$isUserLoggedIn) {
// echo html and code for login
} else {
// echo html and code for welcome
}
I suppose that you want an action/view that can be rendered by both logged and not logged in users.
Similar to riky's the following code might help you
In your controller:
//check if user is logged in and set $user_details variable in the view
if($this->Auth->User()){
$user_details = $this->Auth->User();
}
$this->set(compact('user_details'));
In your view:
<? //check if $user_details variable is set (user is logged in) and display the correct element
if(isset($user_details){
echo $this->element('welcome_box',array('user_details'=>$user_details));
}else{
echo $this->element('login_box');
}
?>
My welcome controller coded like this,
function index()
{
// some code here to set up my table
echo $this->table->generate();
$data['heading'] = "My Real Heading";
$this->load->view('view_page', $data);
}
When I open http://localhost/ci/index.php/welcome/
I found the table generated successfully. but how can I place my table showed under my Heading?
My confused that, the table class generated by module function. It will finished before the view page load. That's why the issue occurred.
[Updated].
I found echo $this->table->generate(); could be place into my view page. It works now.
function index()
{
// some code here to set up my table
$data['myTable'] = $this->table->generate();
//assign result to a variable in the $data array
$data['heading'] = "My Real Heading";
$this->load->view('view_page', $data);
}
in your view:
<!-- html -->
echo $heading;
echo $myTable;