Hi guys i am first time in coding codeigniter and my create CMS upload image and show in slider and my error is backtrace and this is my code View.php
<section class="home-slider owl-carousel">
<?php foreach($data as $row) { ?>
<div class="slider-item" style="background-image: url(); width: auto; background-repeat:no-repeat; background-size: contain; background-position:center;">
<div class="container">
<div class="row slider-text align-items-center">
</div>
</div>
</div>
<?php } ?>
model.php
<?php
class HomeModel extends CI_Model {
function __construct() {
parent::__construct();
}
public function selectAllData() {
$this->db->select("file_name,description");
$this->db->from('tbl_slider');
$query = $this->db->get();
return $query->result();
} }
controller.php
class Home extends CI_Controller {
function __construct() {
parent::__construct();
}
function index(){
$this->load->model('HomeModel');
$data['all_data'] = $this->HomeModel->selectAllData();
$this->templates('home_index', $data);
}
function templates($page) {
$this->load->view('templates/header');
$this->load->view($page);
$this->load->view('templates/navbar');
$this->load->view('templates/footer');
$this->load->view('templates/footer-js');
}
}
thank you for respond
You need to set some height and url of background image as below :
<section class="home-slider owl-carousel">
<?php foreach ($data as $row) { ?>
<div class="slider-item" style="background-image: url(demo.jpg); height: 200px; width: auto; background-repeat:no-repeat; background-size: contain; background-position:center;">
<div class="container">
<div class="row slider-text align-items-center">
</div>
</div>
</div>
<?php } ?>
</section>
Related
I can't load index.php file in view folder. The error displayed is
"Unable to load the requested file: calendar/index.php"
Here is the code
controller(Calendar.php):
*public function __construct() {
Parent::__construct();
$this->load->model("calendar_model");
}
public function index()
{
$this->load->view("calendar/index.php", array());
}*
model(Calendar_model.php):
*?php
class Calendar_Model extends CI_Model
{
}
?>*
view (index.php):
*<div class="container">
<div class="row">
<div class="col-md-12">
<h1>Calendar</h1>
<div id="calendar">
<script type="text/javascript">
$(document).ready(function() {
$('#calendar').fullCalendar({
});
});
</script>
</div>
</div>
</div>
</div>
<script type="text/javascript">
$(document).ready(function() {
});
</script>*
Better rename your index.php like V_index.php
for this case remove .php from your code
public function __construct()
{
Parent::__construct();
$this->load->model("calendar_model");
}
public function index()
{
$this->load->view("calendar/index", array());
}
So I'm in the middle of creating an E-Commerce site for a class. On my Profile page I'm planning to display various info stored in the db. Right now I'm only messing with the user photo. I have a function in the model that gets the Users photo from the column 'Image_Path' in DB 'users'. My problem is that for each profile view it shows the same photo. I think its return the whole array of pictures and maybe just sets it as the first one?
here is the model
<?php
class Profile_Model extends CI_Model
{
public function __construct()
{
$this->load->database();
}
// public function get_profile_picture()
// {
//
// $query = $this->db->get('users');
// return $query -> result();
// }
public function get_single_profile($id){
//get whole table
$this->db->select('Username');
$this->db->select('Image_Path');
$this->db->from('users');
$this->db->where('User_ID', $id);
$query = $this->db->get();
return $query->result();
}//end get_single_profile
//for uploading profile pics
public function set_profile_pic(){
}
}//CLASS
?>
The Controller
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Profile extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->helper('form');
$this->load->helper('url');
$this->load->library('session'); //needed to use global session variables
$this->load->helper('language');
$this->load->model('Profile/Profile_Model');
}
public function index()
{
if($this->session->userdata('logged_in'))
{
$data['profilepicture'] = $this->Profile_Model->get_single_profile();
$this->load->view('Profile/Profile', $data);
}// echo session variable logged_in
else{
redirect( base_url().'Login'); //redirect to user profile view after verification)
}
}//END Index
public function logout(){
$this->session->sess_destroy();
redirect(base_url(). 'Login');
}//END LOGOUT
public function display_profile_pic(){
$data['profilepicture'] = $this->Profile_Model->get_profile_picture();
$this->load->view('Product/Product', $data);
}
}//END CLASS
The View
<!DOCTYPE html>
<html>
<head>
<title><?php echo $_SESSION['logged_in']?></title>
<style type="text/css">
.container {
width: 15%;
text-align: center;
clear:both;
}
.container input {
width: 100%;
clear: both;
}
.logout {
position: fixed;
bottom: 10%;
right: 10%;
}
.aboutme{
position:fixed;
right:50%;
bottom:50%;
}
.shopbutton{
position:fixed;
right:17%;
top:10%;
}
.checkout{
position:fixed;
right:10%;
top:10%;
}
</style>
</head>
<body>
<h3>Logged In As: <?php echo $_SESSION['logged_in']?> </h3>
**where the picture is displayed
<?php foreach ($profilepicture as $row)
{
echo '<img src='.base_url().'../'.$row->Image_Path.' style="Height: 300px; Width:200px;"><br>';
} ?>
<form action=" <?php echo base_url().'Profile';?>" method='post'>
<input type='submit' value='Upload Picture'>
</form>
<div class = 'aboutme'>
<p>About Me</p>
</div>
<div class = 'logout'>
<form action= '<?php echo base_url().'Profile/logout';?>' method='post'>
<input type="submit" value="Log Out">
</form>
</div>
<div class = 'checkout'>
<form action = '<?php echo base_url().'Cart/display_cart';?>' method='post'>
<input type='submit' value='Check Out'>
</form>
</div>
<div class = 'shopbutton'>
<form action = '<?php echo base_url().'Product/display_products';?>' method='post'>
<input type='submit' value='Shop'>
</form>
</div>
</body>
</html>
First, try changing the select portion of your query. It should be like:
$this->db->select('Image_Path, Username');
if it still not working, try to echo your last query in get_single_profile()
echo $this->db->last_query();
exit;
Changed my Model function to:
public function get_single_profile($id){
//get whole table
$this->db->select('Image_Path');
$this->db->from('users');
$this->db->where('Username', $id);
$query = $this->db->get();
echo $this->db->last_query();
return $query->result();
}//end get_single_profile
And My Controller Index To:
public function index()
{
if($this->session->userdata('logged_in'))
{
$data['profilepicture'] = $this->Profile_Model->get_single_profile($this->session->userdata('logged_in') );
$this->load->view('Profile/Profile', $data);
}// echo session variable logged_in
else{
redirect( base_url().'Login'); //redirect to user profile view after verification)
}
}//END Index
in the model I changed the Username from the table and set it to $id, In the controller I used a previously defined session variable to set $id to the session...I think
I just started learning OpenCart, currently using version 2.3.0.2 .
I created a module, everything works fine on the backend.
On the frontend however, when I return the template from the controller it shows up blank.
But if I add a die(); in the template it loads the template.
Controller code:
<?php
class ControllerExtensionModuleHelloworld extends Controller {
public function index() {
$this->load->language('extension/module/helloworld');
$data['heading_title'] = $this->language->get('heading_title');
$data['helloworld_value'] = html_entity_decode($this->config->get('helloworld_text_field'));
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/extension/module/helloworld.tpl')) {
// print_r(__LINE__);
return $this->load->view($this->config->get('config_template') . '/template/extension/module/helloworld.tpl', $data);
} else {
// print_r(__LINE__);
return $this->load->view('extension/module/helloworld.tpl');
}
}
}
Template code:
<div class="panel panel-default">
<div class="panel-heading"> <?php echo $heading_title; ?> </div>
<div class="panel-content" style="text-align: center;"> <?php echo $helloworld_value; ?> </div>
<div style="height:100px;width:100px;background-color:blue;"></div>
</div>
Fixed it by changing:
return $this->load->view('extension/module/helloworld.tpl', $data);
To:
$this->response->setOutput($this->load->view('extension/module/helloworld.tpl', $data));
I have the following shortcodes in a page or post:
[custom_width width='500' color='red']
[custom_width width='600' color='blue']
The shortcode function is to display 2 buttons with their respective width. The problem is that the buttons are displayed the same width using the last width of 600.
The function:
<?php
function xyz ($attr) {
$xyzwidth = $attr['width'];
$xyzcolor = $attr['color'];
my_style($xyzcolor);
?>
<style type="text/css">
.mystyle {
width: <?php echo $xyzwidth; ?>px;
}
</style>
<div class="mystyle">
My Text
</div>
<?php } ?>
note: the rest of the css is in its own .css file
function my_style($xyzcolor) {
switch ($xyzcolor) {
case 'red': my_red();
break;
case 'blue': my_blue();
break;
}
<?php function my_red() { ?>
<style type="text/css">
.mystyle {
............
}
.mystyle: hover {
............
}
.mystyle a {
............
}
.mystyle a:hover {
............
}
</style>
<?php } ?>
If you're using the same class (mystyle) on both buttons, the last width defined on that class will apply to both elements.
For your purposes, you're probably better off with:
<?php
function xyz ($attr) {
$xyzwidth = $attr['width'];
?>
<div style="width: <?php echo $xyzwidth; ?>px">
My Text
</div>
<?php
}
?>
Define your blue and red CSS in general. Not in your loop every time. Something like this:
<style type="text/css">
// red
.mystyle.red {
............
}
.mystyle.red:hover {
............
}
.mystyle.red a {
............
}
.mystyle.red a:hover {
............
}
// blue
.mystyle.blue {
............
}
.mystyle.blue:hover {
............
}
.mystyle.blue a {
............
}
.mystyle.blue a:hover {
............
}
</style>
And in your xyz function, give your div the desired class, and set the width of div internal:
<?php
function xyz ($attr) {
$xyzwidth = $attr['width'];
$xyzcolor = $attr['color'];
my_style($xyzcolor);
?>
<div class="mystyle <?php echo $xyzcolor; ?>" style="width: <?php echo $xyzwidth; ?>px;">
My Text
</div>
<?php } ?>
The CSS that I'm attempted to attach to 'echo $tube->error;' is not showing.. It just shows as default black text as if it had no css... How would I fix this?
Thanks (:
Below is what I need to fix..
The html/php part:
<div id="error">
<pre>
<?php } else {
echo $tube->error;
}
}
?>
</pre>
</div>
The html/php part in context:
<?php
if(isset($_POST['url']))
{
include('curl.php');
include('youtube.php');
$tube = new youtube();
$links = $tube->get($_POST['url']);
if($links) { ?>
<div id="result">
<b>Download Links ( Same IP Downloading only )</b> :
<?php
$format = '<p>Download video.%s - %s<br/>Right-click download link and choose etc...</p>';
while($link = array_shift($links))
{
echo vsprintf($format,$link);
}
?>
</div>
<div id="error">
<pre>
<?php } else {
echo $tube->error;
}
}
?>
</pre>
</div>
The CSS:
#error {
width:404px;
margin-left: auto;
margin-right: auto;
font-size:12;
font-family: 'Dosis', sans-serif;
color:white;
padding-top:20px;
}
The part of youtube.php(additional info.. not sure if you guys need this):
function get($url)
{
$this->conn = new Curl('youtube');
$html = $this->conn->get($url);
if(strstr($html,'verify-age-thumb'))
{
$this->error = "Adult Video Detected";
return false;
}
if(strstr($html,'das_captcha'))
{
$this->error = "Captcah Found please run on diffrent server";
return false;
}
if(!preg_match('/stream_map=(.[^&]*?)&/i',$html,$match))
{
$this->error = "Error Locating Downlod URL's";
return false;
}
Thanks again for any help!!
EDIT: I was wrong, it wasn't a CSS error, but a construct error, as others have noticed. I just rewrote the "The html/php part in context" to make it more clear and hopefully working:
<?php
if(isset($_POST['url']))
{
include('curl.php');
include('youtube.php');
$tube = new youtube();
$links = $tube->get($_POST['url']);
if($links)
{
?>
<div id="result">
<b>Download Links ( Same IP Downloading only )</b> :
<?php
$format = '<p>Download video.%s - %s<br/>Right-click download link and choose etc...</p>';
while($link = array_shift($links))
{
echo vsprintf($format,$link);
}
?>
</div>
<?php
}
else
{
?>
<div id="error">
<pre>
<?php echo $tube->error; ?>
</pre>
</div>
<?php
}
}
?>
Hope everything is ok now :)
Try this code:
<?php
if (isset($_POST['url'])) {
include('curl.php');
include('youtube.php');
$tube = new youtube();
$links = $tube->get($_POST['url']);
if ($links) {
?>
<div id="result">
<b>Download Links ( Same IP Downloading only )</b> :
<?php
$format = '<p>Download video.%s - %s<br/>Right-click download link and choose etc...</p>';
while($link = array_shift($links)) {
echo vsprintf($format,$link);
}
?>
</div>
<?php } else { ?>
<div id="error">
<pre>
<?php echo $tube->error; ?>
</pre>
</div>
<?php } } ?>
Don't forget to include the CSS... and please, please write more readable in the future.
Your <div id="error"> is never rendered if there is an error, because your else statement only includes the error text itself. Move the div and pre inside the else to get it working.
<?php } else { ?>
<div id="error">
<pre>
<?php echo $tube->error; ?>
</pre>
</div>
<?php } ?>
Try this css:
#error pre {
width:404px;
margin-left: auto;
margin-right: auto;
font-size:12;
font-family: 'Dosis', sans-serif;
color:white;
padding-top:20px;
}
Try to define your CSS also for #error pre and not only #error:
div#error {
width:404px;
margin-left: auto;
margin-right: auto;
padding-top:20px;
}
div#error pre
{
font-size:12;
font-family: 'Dosis', sans-serif;
color:white;
}
Use also an inspector (like Chrome's one, that you call with CTRL+I) to make sure:
- there are not overrides that undo there lines
- CSS is properly loaded (if in an external file)