Unable to load the requested file: category.php - php

I have the unable to load the requested file error When the site is visited. The product which is the first page to be displayed shows the above error so as all product related functions like the product details and the product category respectively.
Below is my products class showing the method that gets all the product, product details and categories.
defined('BASEPATH') OR exit('No direct script access allowed');
class Products extends CI_Controller {
public function index()
{
// Get all products
$data['products'] = $this->Product_model->get_products();
// Load View
$data['main_content'] = 'products';
$this->load->view('layouts/main',$data);
}
public function details($id)
{
// Get all products details
$data['product'] = $this->Product_model->get_product_details($id);
// Load View
$data['main_content'] = 'details';
$this->load->view('layouts/main',$data);
}
public function category($id)
{
// Get all products details
$data['products'] = $this->Product_model->get_category_details($id);
// Load View
$data['main_content'] = 'category';
$this->load->view('layouts/main',$data);
}
}
And below is the Product View
<?php if($this->session->flashdata('registered')) : ?>
<div class="alert alert-success panel-body">
<?php echo $this->session->flashdata('registered');?>
</div>
<?php endif;?>
<?php if($this->session->flashdata('pass_login')) : ?>
<div class="alert alert-success panel-body">
<?php echo $this->session->flashdata('pass_login');?>
</div>
<?php endif;?>
<?php if($this->session->flashdata('fail_login')) : ?>
<div class="alert alert-danger panel-body">
<?php echo $this->session->flashdata('fail_login');?>
</div>
<?php endif;?>
<?php foreach($products as $product): ?>
<div class="col-md-4 game">
<div class="game-price"> <?php echo $product->price;?></div>
<a href="<?php echo base_url();?>products/details/<?php echo $product->id;?>">
<img src=" <?php echo base_url();?>assets/images/products/<?php echo $product->image;?>" />
</a>
<div class="game-title">
<?php echo $product->title;?>
</div>
<div class="game-add">
<form method="post" action="<?php echo base_url();?>cart/add">
QTY:<input class="qty" type="text" name="qty" value="1"/><br>
<input type="hidden" name="item_number" value="<?php echo $product->id;?>"/>
<input type="hidden" name="price" value="<?php echo $product->price;?>"/>
<input type="hidden" name="title" value="<?php echo $product->title;?>"/>
<button class="btn btn-primary" type="submit">Add To Cart</button>
</form>
</div>
</div>
<?php endforeach ?>
Here's my view folder structure

I see you have your view file with upper case Category.php.
There for on controller
public function category($id)
{
// Get all products details
$data['products'] = $this->Product_model->get_category_details($id);
// Load View
$data['main_content'] = 'Category'; // match filename
$this->load->view('layouts/main',$data);
}

Just make sure that you are loading views correctly.
you can share your views folder structure with us to lookup this problem

Related

Images not loading on page when I call the view using a different model function

I have created a method in a model to call all events from a database with images - this worked fine I then wanted to find ones that match a postcode so created another function which is called when a search bar is filled in and submitted. This other function works and loads all info from database except the images even the one that is hardcoded in the index page - I can't work out what I have done wrong or why it won't work.
I have tested the code in phpMyAdmin and the function returns the image-path, the index page must be okay because it returns everything on the other function which leaves the controller but i can't see anything wrong there either.
The model function code:
function FindEventByPostcode($id){
$this->db->query("SELECT
concert.concert_id as concertId,
event_type.id as typeId,
concert.type_id as typeCId,
concert.concert_name as concertName,
concert.date as concertDate,
users.name as userName,
concert.date as date,
concert.post_code as post_code,
concert.info as info,
images.image_path as imagePath,
event_type.type as type
FROM concert
JOIN event_type
ON concert.type_id = event_type.id
JOIN users ON
users.id = concert.user_id
JOIN images ON concert.image_id = images.id
WHERE concert.post_code = :post_code
ORDER BY concert.date DESC"
);
$this->db->bind(':post_code', $id);
$results = $this->db->resultSet();
return $results;
}
The controller code:
$events = $this->eventModel->getEventTypes();
class Pages extends Controller {
public function __construct(){
$this->eventModel = $this->model('Event');
$this->userModel = $this->model('User');
$this->pageModel = $this->model('Page');
}
public function index(){
if(isLoggedIn()){
redirect('profiles');
}
if($_SERVER['REQUEST_METHOD'] == 'POST'){
$postcode = ($_REQUEST['post_code']);
$event = $this->pageModel->FindEventByPostcode($postcode);
$data =[
'title' => 'Forthcoming Events',
'events' => $event
];
$this->view('pages/index', $data);
}else{
$data = [
'title' => 'Forthcoming Events',
'events' => $events
];
$this->view('pages/index', $data);
}
}
}
The Index Page:
<?php require_once APPROOT . '/views/inc/header.php' ?>
<div>
<p>Event Finder</p>
<form name="postcode" method="post"
action="<?php echo URLROOT; ? >/pages/index">
<input type="text" name='post_code'/>
<input type="submit" value="find event">
</form>
</div>
<div class="col-md-6">
<h1><?php echo $data['title'] ?></h1>
</div>
<img src="img/concertBanner.jpg" style="width:100%"/>
<?php foreach($data['events'] as $post) : ?>
<div class="card card-body mb-3">
<img class="card-img-top" src="img/<?php echo $post->userName; ?>/
<?php echo $post->imagePath; ?>"
style="width:50%; height:50%;" alt="Card image cap">
<div class="card-body">
<h4 class="card-title"><?php echo $post->concertName; ?></h4>
<p class="card-text"> Event Info: <?php echo $post->info ?></p>
<p class="card-text"><?php echo $post->type ?></p>
<p></p>
<div class="bg-light p-2 mb-3">
Organised by <?php echo $post->userName; ?>
on <?php echo $post->date; ?>
</div>
<p class="card-text"><?php echo $post->concertName; ?> in
<?php echo $post->post_code; ?> </p>
<a href="<?php echo URLROOT; ?>/pages/show/
<?php echo $post->concertId;?>" class="btn btn-dark">More</a>
</div>
</div>
No error messages just a broken image link instead of the image.

Product category function not working in CodeIgniter

I'm making a website in CodeIgniter and I'm trying to make a menu bar with all the categories, and when you click on a certain category it must show all the products that are in that category but its not really working.
The categories are showing on the category side menu bar, but when I click on a certain category link its going to the right view page but instead of the product information I'm getting this error:
A PHP Error was encountered
Severity: Error
Message: Cannot use object of type stdClass as array
Filename: views/category.php
Line Number: 41
Backtrace:
Line 41 in category.php is this line:
<a href="<?php echo base_url() ?>/Product/details/<?php echo $product['product_id']; ?>">
So I'm guessing it can't echo product detail information?
Here is my Allecadeaus controller to echo products:
<?php
class AlleCadeausController extends CI_Controller {
public function index()
{
$this->load->model('Product_model');
$this->load->model('allecadeaus_model');
$data['products'] = $this->allecadeaus_model->get_products();
$this->load->view('allecadeaus', $data);
}
}
My Allecadeaus_model model file which I use to echo products:
<?php
class Allecadeaus_model extends CI_Model {
public function __construct()
{
parent::__construct();
}
public function get_products()
{
$query = $this->db->query('SELECT * FROM products');
$result = $query->result_array();
return $result;
}
}
category.php view file:
<?php include_once ('templates/header.php'); ?>
<!-- Alle cadeaus gele title bovenaan pagina -->
<div class="container-fluid">
<div class="row">
<div class="col-lg-12 bg-warning" style="font-size:25px">
<center>Alle cadeaus</center>
</div>
</div>
</div>
<hr />
<br>
<!-- Cadeau categorie side menu -->
<div class="container-fluid">
<div class="row">
<div class="col-md-4">
<div id="categorymenu">
<center> <h3>Categorieën</h3> </center>
<ul class="list-group">
<?php foreach (get_categories_h() as $category) : ?>
<li class="list-group-item">
<?php echo $category->name; ?>
</li>
<?php endforeach; ?>
</ul>
</div>
</div>
<!-- Laat cadeau zien op alle cadeaus pagina -->
<div class="col-md-8">
<?php foreach($products as $product) : ?>
<div class="col-md-2">
<div id="product">
<a href="<?php echo base_url() ?>/Product/details/<?php echo $product['product_id']; ?>">
<img src="<?php echo base_url(); ?>upload/<?php echo $product['product_foto_thumb']; ?>">
</a>
<div class="product_naam"><?php echo $product['product_naam']; ?></div>
<div class="ophaal_plaats">
<?php echo $product['ophaal_plaats']; ?>
</div>
<div class="aangeboden_door">
<p>Aangeboden door: Peter</p>
</div>
</div>
</div>
<?php endforeach; ?>
</div>
<div class="clearfix"></div>
<?php include_once ('templates/footer.php'); ?>
My whole allecadeaus.php view file:
<?php include_once ('templates/header.php'); ?>
<!-- Alle cadeaus gele title bovenaan pagina -->
<div class="container-fluid">
<div class="row">
<div class="col-lg-12 bg-warning" style="font-size:25px">
<center>Alle cadeaus</center>
</div>
</div>
</div>
<hr />
<br>
<!-- Cadeau categorie side menu -->
<div class="container-fluid">
<div class="row">
<div class="col-md-4">
<div id="categorymenu">
<center> <h3>Categorieën</h3> </center>
<ul class="list-group">
<?php foreach (get_categories_h() as $category) : ?>
<li class="list-group-item">
<?php echo $category['name']; ?>
</li>
<?php endforeach; ?>
</ul>
</div>
</div>
<!-- Laat cadeau zien op alle cadeaus pagina -->
<div class="col-md-8">
<?php foreach($products as $product) : ?>
<div class="col-md-2">
<div id="product">
<a href="<?php echo base_url() ?>/Product/details/<?php echo $product['product_id']; ?>">
<img src="<?php echo base_url(); ?>upload/<?php echo $product['product_foto_thumb']; ?>">
</a>
<div class="product_naam"><?php echo $product['product_naam']; ?></div>
<div class="ophaal_plaats">
<?php echo $product['ophaal_plaats']; ?>
</div>
<div class="aangeboden_door">
<p>Aangeboden door: Peter</p>
</div>
</div>
</div>
<?php endforeach; ?>
</div>
<div class="clearfix"></div>
<?php include_once ('templates/footer.php'); ?>
My Product.php controller file:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Product extends CI_Controller {
var $data = array();
public function index()
{
//Laad kado uploaden view
$this->load->view('product_form', $this->data);
}
public function details($product_id)
{
//load the Product_model
$this->load->model('Product_model');
//call function getdata in de Product_model
$data['userdetail_list'] = $this->Product_model->getdata();
//get product details
$data['product'] = $this->Product_model->get_product_details($product_id);
//laad view
$data['main_content'] = 'details';
$this->load->view('details',$data);
}
//categorie product function
public function category($id)
{
$data['title'] = 'Category';
$data['page'] = 'Product/category';
$data['category'] = $this->Category_model->findByCategory($id);
$data['products'] = $this->Product_model->findByCategory($id);
$this->Category_model->findByCategory($id);
$this->load->view('category', $data);
}
public function __construct()
{
parent::__construct();
$this->load->model('Product_model');
$this->load->helper(array('form', 'url'));
}
My Product_model file:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Product_model extends CI_model {
public function saveProduct($data) {
$this->db->insert('products', $data);
$product_id = $this->db->insert_id();
return $product_id;
}
public function getdata()
{
$this->db->select('users.user_id,users.email,users.voornaam,products.product_id,products.category_id,products.product_naam');
$this->db->from('users');
$this->db->join('products','products.user_id = users.user_id');
$query = $this->db->get();
if($query->num_rows()>0)
{
return $query->result_array();
}
}
public function get_product_details($product_id) {
$arrReturn = array();
$this->db->select('*');
$this->db->from('products');
$this->db->where('product_id', $product_id);
$query = $this->db->get();
$result = $query->result_array();
if (!empty($result)) {
$arrReturn = $result[0];
}
return $arrReturn;
}
/*
Get categories
*/
public function get_categories(){
$this->db->select('*');
$this->db->from('categories');
$query = $this->db->get();
$result = $query->result();
return $result;
}
public function findAll(){
return $this->db->get('products')->result();
}
public function findByCategory($id){
$this->db->where('id', $id);
return $this->db->get('categories')->result();
}
}
?>
My Category_model file:
<?php
class Category_model extends CI_Model {
public function findAll(){
$this->db->get('categories')->result();
}
public function findByCategory($id)
{
$this->db->where('id', $id);
$this->db->get('categories')->result();
return $this->db->get('categories')->row();
}
}
?>
My db_helper.php
<?php if (!function_exists('get_categories_h')) {
function get_categories_h(){
$CI = get_instance();
$categories = $CI->Product_model->get_categories();
return $categories;
} } ?>
Some database information:
Table 1: 5 columns: products
-product_id
-product_naam
-product_beschrijving
-user_id
-category_id
table 2: categories: 2 columns:
1.id
2.name
You can try this solution for your problem:
Whole allecadeaus.php view file:
<ul class="list-group">
<?php foreach (get_categories_h() as $category) : ?>
<li class="list-group-item">
<?php echo $category->name; ?>
</li>
<?php endforeach; ?>
</ul>
is your database already have the filed category_id, is the name correct? can you show screen from your categories and products table?

Link to a user profile page in codeigniter

I'm trying to make a function in the CodeIgniter framework so users can click on product detail page, and see which user uploaded that certain product and they must be able to click on the product owner to go to his profile page.
Now, I am already able to echo owner information of the product owner on the details page. But the link to the owner profile page is not working some reason and the name isn't echoed anymore since I tried to make it a link.
This is my product details page (details.php) foreach loop function where I'm trying to echo the username of the owner of a product and link it to their profile page:
<?php include_once ('templates/header.php'); ?>
<div class="container">
<h3>Email van de eigenaar:</h4>
<?php
foreach($userdetail_list as $row)
{
?>
<tr>
<td><?php echo $row['email'];?></td>
</tr>
<?php } ?>
</div>
<div class="container">
<div class="row">
<div class="col-md-4" style="margin-top:24px;">
<img src="<?php echo base_url(); ?>upload/<?php echo $product['product_foto']; ?>" class="img-responsive">
</div>
<div class="col-md-5">
<h1> <div class="product_naam"> <?php echo $product['product_naam']; ?> </div> </h1>
<h3>Over dit cadeau</h3>
<div class="product_beschrijving"><?php echo $product['product_beschrijving']; ?> </div>
</div>
<div class="col-md-3">
<button type="button" class="btn btn-default">Cadeau aanvragen</button>
<div class="aangeboden_door"> Aangeboden door: <?php
foreach($userdetail_list as $row)
{
?>
<tr>
<td><?=$row['username']; ?></td>
<td><?php echo $row['email'];?></td>
</tr>
<?php } ?>
</div>
</div>
</div>
</div>
<div class="container">
<footer>
<p>© kadokado 2017, Inc.</p>
</footer>
<hr>
</div>
<div class="clearfix"></div>
<?php include_once ('templates/footer.php'); ?>
When I load the view page I do not see the username and no link to the users profile.
Here is my controller (User.php):
<?php
class User extends CI_Controller
{
public function index()
{
$this->load->view('profile', $data);
}
public function __construct()
{
parent::__construct();
if ($_SESSION['user_logged'] == FALSE) {
$this->session->set_flashdata("error", "Please login first to view this page!! ");
redirect("auth/login");
}
}
public function userdetails($user_id)
{
//load the User_model
$this->load->model('User_model');
//call function getdata in de Product_model
$data['userdata_list'] = $this->User_model->getdata();
//get product details
$data['user'] = $this->User_model->get_user_info($user_id);
//laad view
$data['main_content'] = 'profiel_user';
$this->load->view('profiel_user',$data);
}
public function profile()
{
$this->load->model('User_model');
if ($_SESSION['user_logged'] == FALSE) {
$this->session->set_flashdata("error", "Please login first to view this page!! ");
redirect("auth/login");
}
$this->load->view('profile');
}
}
full model file (User_model.php)
<?php
class User_model extends CI_Model {
public function getUserInfoByEmail($email)
{
$q = $this->db->get_where('users', array('email' => $email), 1);
if($this->db->affected_rows() > 0){
$row = $q->row();
return $row;
}else{
error_log('no user found getUserInfo('.$email.')');
return false;
}
}
public function getUserInfo($user_id)
{
$q = $this->db->get_where('users', array('user_id' => $user_id), 1);
if($this->db->affected_rows() > 0){
$row = $q->row();
return $row;
}else{
error_log('no user found getUserInfo('.$user_id.')');
return false;
}
}
public function getdata()
{
$this->db->where('user_id', $id);
$this->db->from('users');
$query = $this->db->get();
if($query->num_rows()>0)
{
return $query->result_array();
}
}
}
?>
Problably because of this line:
<?=$row['username']; ?>
Maybe your server does not support short hand tags?
try this:
<?php echo $row['username']; ?>
You also missed a semicolon here at the end:
echo base_url() . 'User/profiel_user?id='.$row['user_id']
and also here:
<a href="<?php echo base_url() ?>/Cadeauaanvragen">
You also use table row and table data tags without a surrounding table tag. Or remove all tr and td tags.
See: How do browsers analyze <tr> <td> without <table>?

WordPress sidebar inside get category id and get current post row number

I'm using newspaper7 theme for WordPress and have inside td_module_mx16 the following code:
<?php
class td_module_mx16 extends td_module {
function __construct($post) {
//run the parrent constructor
parent::__construct($post);
}
function render() {
ob_start();
?>
<div class="<?php echo $this->get_module_classes();?>">
<div class="meta-info-container ">
<div class="td-info-container">
<div class="td-module-image">
<?php echo $this->get_image('td_356x364');?>
<?php if (td_util::get_option('tds_category_module_mx16') == 'yes') { echo $this->get_category(); }?>
</div>
<div class="td-item-details">
<div class="td-module-meta-info ">
<?php echo $this->get_date();?>
<? // php echo $this->get_category();?>
<?php echo $this->get_comments();?>
</div>
<div class="td-excerpt">
<?php echo $this->get_title();
?>
<?php // echo $this->get_excerpt();?>
</div>
<?
/*
<div class="td-read-more">
<?php echo __td('Read more', TD_THEME_NAME);?>
</div>
*/
?>
</div>
</div>
</div>
</div>
<?php return ob_get_clean();
}
}
In this file inside I want to get:
CATEGORY ID for each listing post
AND ROW number for each post like (title near 1,2,3,4,5)
Any idea?

Pick from a list and save it to database

I am creating a website with Codeigniter 3 HMVC style for a client and he wants have a function on this page where the logged user has the choice of picking their own news. For example if a user chooses Juventus then he will recieve all the news added where Juventus is named. Basically like a add to basket or cart thing and I have never done something like this so here is what I have created:
Controller
class Usernews extends MY_Controller{
function __construct() {
parent::__construct();
$this->load->model('model_usernews');
$this->load->module('template');
}
function search(){
$data['pageTitle'] = "User news";
$search_name = $this->input->post('band');
$data['bands'] = $this->model_usernews->get_clubs($search_name);
$data['module'] = "usernews";
$data['view_file'] = "usernews";
$this->template->user_news($data);
}
}
Model
class Model_usernews extends CI_Model {
function get_table(){
$table = "bands";
return $table;
}
function get_clubs($keyword) {
$table = $this->get_table();
$this->db->like('band_name', $keyword, 'both');
$this->db->order_by('band_name');
$query=$this->db->get($table);
return $query;
}
and part of the View
<div class="row">
<div class="col-lg-8 ">
<!-- USER BAND LIST -->
<!-- LIST OF ARTICLES -->
</div>
<div class="col-lg-4">
<div class="row">
<?php $attributes = array('id' => 'list_of_bands');
echo form_open('usernews/search',$attributes); ?>
<input type="text" class="form-control" name="band"
placeholder="Search">
<button type="submit" class="btn btn-default btn-lg" >OK</button>
<?php echo form_close(); ?>
<?php $num_rows = $listing->num_rows();
if($num_rows > 0){ ?>
<ul id="the_bands" class="list-unstyled">
<li> <?php foreach ($listing->result() as $row){?>
<li><?php echo $row->band_name; ?>" ><button id="add_band"
class="btn btn-default btn-sm" >Add to list</button></li>
<?php }
} else{
echo "<p>No bands with that name</p>";
} ?>
</div>
</div>
I can search for the bands in the database but now I am clueless.
In your view use $bands instead of $listing.

Categories