Am creating an ecommerce website but I don't know how to display the details of a a elected product with its price. Any help will be greatful. Thanms
↧
How to.create a products' detail.page using shopping cart library
↧
Query Builder: regex error when passing large array to where_in
CI 3.1.9
PHP 5.6.38
FreeBSD 11.2
Apache 2.4
MySQL 5.7
Problem: passing a large array to where_in generates the php error and the update fails.
Background:
I need to be able to generate this SQL:
Query builder cannot use db->join() with db->update(), so my solution is to use query builder and break the query into two. One to pull the attribute_id's that share the definition_id that I want and put them in an array. and the second is to update the attribute_values table by setting the attribute_value to the attribute_datetime.
The problem comes in that this array in particular contains large amounts of data (12,000+ items). I'm guessing that since MySQL and QueryBuilder were never designed to have WHERE IN clauses contain more than a small array (that's what joins in updates are for) that my problem is being caused by this. Should I just abandon Query Builder and use query() instead to make my join or is there a good solution that includes query builder that I'm just missing?
PHP 5.6.38
FreeBSD 11.2
Apache 2.4
MySQL 5.7
Problem: passing a large array to where_in generates the php error and the update fails.
Code:
preg_match(): Compilation failed: regular expression is too large at offset 106661 /usr/local/www/public_html/pos_alpha/vendor/codeigniter/framework/system/database/DB_query_builder.php 2418Background:
I need to be able to generate this SQL:
Code:
UPDATE ospos_attribute_values
INNER JOIN ospos_attribute_links
ON ospos_attribute_values.attribute_id = ospos_attribute_links.attribute_id
SET ospos_attribute_values.attribute_datetime = ospos_attribute_values.attribute_value
WHERE ospos_attribute_links.definition_id = [definition_id from PHP]Query builder cannot use db->join() with db->update(), so my solution is to use query builder and break the query into two. One to pull the attribute_id's that share the definition_id that I want and put them in an array. and the second is to update the attribute_values table by setting the attribute_value to the attribute_datetime.
PHP Code:
$this->db->trans_start();
//Get all the attribute_ids I want to update and store them in a simple array
$this->db->select('attribute_id');
$this->db->from('attribute_links');
$this->db->where('definition_id',$definition_id);
foreach($this->db->get()->result_array() as $row)
{
$attribute_ids[] = $row['attribute_id'];
}
//Set the datetime to the value of the value
$this->db->set('attribute_datetime','attribute_value');
$this->db->where_in('attribute_id',$attribute_ids);
$success = $this->db->update('attribute_values');
$this->db->trans_complete();
The problem comes in that this array in particular contains large amounts of data (12,000+ items). I'm guessing that since MySQL and QueryBuilder were never designed to have WHERE IN clauses contain more than a small array (that's what joins in updates are for) that my problem is being caused by this. Should I just abandon Query Builder and use query() instead to make my join or is there a good solution that includes query builder that I'm just missing?
↧
↧
setting up CI on a new PC
I am moving my app over to a Linux development machine. I am wondering where is the best place to install CI? Should I install it in /var/www/html/my_dir ? That is the document root + my_dir. Or is there a better place to put it?
↧
Add table and fieldname
Hi. im going to add database table and field and of course the field type,auto_increment and so on.. and
may i ask what what is wrong with this?
Thanks
may i ask what what is wrong with this?
PHP Code:
$tblname = $this->input->post('tblname');
$fldname = $this->input->post('fld_name[]');
$fldtype = $this->input->post('fld_type');
$fldauth = $this->input->post('fld_aut');
$fldlgth = $this->input->post('fld_lgth');
for($i = 0; $i < count($fldname); $i++)
{
$insert = [[$fldname] => ['type' => $fldtype,
'auto_increment' => $fldauth,
'constraint' => $fldlgth,
'null' =>TRUE]];
$this->dbforge->add_field($insert);
$this->dbforge->add_key($fldname, TRUE);
$this->dbforge->create_table($tblname, TRUE);
}
Thanks
↧
No Model errors reported when calling Global Controller Method
I am in the process of updating a standalone MySqli/Pdo database that creates SVG Charts (courtesy of HighCharts) and was most surprised when the imported script did not show the Chart (which are shown in the Standalone Version).
The Model:
The addHour2UKTime method is in the Global Controller and not only is it not called but there is no errors or warning shown and var_dump($tmp); returns NULL !!!!!
I tried adding the following NameSpace to the Model and it is still not called and once again with no errors or warnings shown?
use App\Libraries\L_Super;
I was able to call the method by adding to the Model:
private function addHour2UKTime(...) .
Is this a NameSpace problem or am I expecting too much from the Models?
The Model:
PHP Code:
<?php
declare(strict_types=1);
namespace App\Models;
error_reporting(-1);
ini_set('display_error$', 'true');
use CodeIgniter\Model;
// use App\Libraries\L_Super;
// var_dump( get_class_methods('CodeIgniter\Model\M_ci4'));
//=======================================
class M_ci4 extends Model
{
protected $db;
//=============================
public dbWriteCsv(
string $fCsv,
int $iDevId=0,
string $sensorName='NO NAME???'
)
:int
{
//
//
//
$tmp = $this->_addHour2UKTime((string) $row->tstamp, $lBKK=false);
var_dump($tmp); // returns NULL
die;
I tried adding the following NameSpace to the Model and it is still not called and once again with no errors or warnings shown?
use App\Libraries\L_Super;
I was able to call the method by adding to the Model:
private function addHour2UKTime(...) .
Is this a NameSpace problem or am I expecting too much from the Models?
↧
↧
Where if
Excuse my bad English!
How can i use if statement in where Codeigniter
How can i use if statement in where Codeigniter
↧
Could not login with the correct credentials after downloading remote site
I copied a remote CI site onto my local dev environment via FTP. After tweaking the config files to get it working locally, I then created the DB by importing the remote DB. The site uses Ion Auth for user credentials.
However, I could not login with the correct credentials. The error was "incorrect login".
I bypassed this error by manually overwriting the bcrypted password in the database with another generated bcrypted password.
Does anyone know why this problem happens?
Thanks.
However, I could not login with the correct credentials. The error was "incorrect login".
I bypassed this error by manually overwriting the bcrypted password in the database with another generated bcrypted password.
Does anyone know why this problem happens?
Thanks.
↧
array array_sum get error message
Results from the table:
I want to sum an income_value value, so the results obtained are 36.00
I have tried this code but always get an error message:
Code:
Array (
[0] => stdClass Object (
[ID] => 00058
[income_campaign] => 00001
[income_country] =>
[income_value] => 0.00
[income_date] => 2019-02-11
)
[1] => stdClass Object (
[ID] => 00056
[income_campaign] => 00001
[income_country] => 1US, 3PH, 2CN, 9TH
[income_value] => 12.00
[income_date] => 2019-02-12
)
[2] => stdClass Object (
[ID] => 00059
[income_campaign] => 00001
[income_country] => 1US
[income_value] => 12.00
[income_date] => 2019-02-10
)
[3] => stdClass Object (
[ID] => 00061
[income_campaign] => 00001
[income_country] => 2US
[income_value] => 12.00
[income_date] => 2019-02-09
)
)I want to sum an income_value value, so the results obtained are 36.00
I have tried this code but always get an error message:
PHP Code:
$sum = array();
foreach ($data['data_user_income'] as $a => $b) {
foreach ($b as $c => $d) {
$sum[$c]+=$d;
}
}
print_r($sum);
// Error message :
// Message: Undefined index: ID,income_value .... etc.
↧
Invisible Recaptcha
I can't seem to find a proper implementation of invisible recaptcha anywhere, all libraries I tried just fail to verify switching to invisible. I noticed that in normal operation the recaptcha asks me to verify using various images, I suspect this is not properly handled in any of the libraries I tried. Is there a working library for v2 invisible recaptcha anywhere that handles this properly or how do I add handling re-verification to it?
↧
↧
the model does not connect
I am using the latest version of Codeigniter, the NetBeans program for the code and XAMPP.
In the controller I have the following code (it's called Sesion.php):
In the model (it's called Usuario.php):
The error:
Note: the function receives the two variables perfectly
I think that it should work but I do not know what happens, I hope you can help me. Regards!
In the controller I have the following code (it's called Sesion.php):
PHP Code:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Sesion extends CI_Controller {
public function __construct() {
parent::__construct();
$this->load->helper('url');
$this->load->library('session');
$this->load->model('usuario');
}
public function index()
{
if (!$this->input->post()) { //SI NO HAY POST
$cuerpo['c1'] = $this->load->view('form_sesion', '', true); //CARGA LA VISTA
$this->load->view('plantilla', array('cuerpo' => $cuerpo));
} else { //SI HAY POST
$usuario = $this->usuario->ExisteUsuario($this->input->post('user'), $this->input->post('pass'));
//MIRAR SI EXISTE EL USUARIO DE QUE TIPO ES
$this->Entrar($usuario); //MANDA A SU CONTROLADOR
}
}
In the model (it's called Usuario.php):
PHP Code:
<?php
class Usuario extends CI_Model{
public function __construct() {
parent::__construct();
}
public function ExisteUsario($user, $pass){
if($user === "usuario" && $pass == "admin") {
return "vale";}
}
}
The error:
PHP Code:
An uncaught Exception was encountered
Type: Error
Message: Call to undefined method Usuario::ExisteUsuario()
Filename: C:\xampp2\htdocs\matsa\application\controllers\Sesion.php
Line Number: 24
Backtrace:
File: C:\xampp2\htdocs\matsa\index.php
Line: 315
Function: require_once
Note: the function receives the two variables perfectly
I think that it should work but I do not know what happens, I hope you can help me. Regards!
↧
Parse error: syntax error, unexpected '::'
Hello,
I defined constants in Otobil_model.php
Then in Controller I am trying to access these constants:
I am getting " Parse error: syntax error, unexpected '::' (T_PAAMAYIM_NEKUDOTAYIM) in \application\controllers\Otobil.php on line 36"
Anybody has idea why I am getting this error?
I already did this in my other projects, but now I am getting this error...
I defined constants in Otobil_model.php
PHP Code:
class Otobil_model extends MY_Model
{
const INDIVIDUAL_TYPE = 'INDIVIDUAL';
const CORPORATE_TYPE = 'CORPORATE';
}
Then in Controller I am trying to access these constants:
PHP Code:
class Otobil extends Public_Controller
{
function __construct()
{
parent::__construct();
$this->load->model('otobil_model');
}
public function apply()
{
$type = $this->otobil_model::CORPORATE_TYPE;
}
}
I am getting " Parse error: syntax error, unexpected '::' (T_PAAMAYIM_NEKUDOTAYIM) in \application\controllers\Otobil.php on line 36"
Anybody has idea why I am getting this error?
I already did this in my other projects, but now I am getting this error...
↧
Database-sample.php
I just interesting in one question, sorry, if it's duplicate thread, but I can't find answer.
I can't understand, why CI don't have a file database-sample.php, like others frameworks. And file database.php must be in .gitignore by default, IMHO. It's easy to have two file database-sample.php and database.php, so why not?
I can't understand, why CI don't have a file database-sample.php, like others frameworks. And file database.php must be in .gitignore by default, IMHO. It's easy to have two file database-sample.php and database.php, so why not?
↧
Custom ENVIRONMENT name
Hi.
I'm trying to use a custom ENVIRONMENT name like 'potato'
but when I define this name
index.php >
I create the folder 'potato' on the config folder
application > config > potato > config.php
And I get this message "The application environment is not set correctly."
If I change to 'testing' or 'development' it works ok.
It's not allowed to create custom development names?
Thanks.
I'm trying to use a custom ENVIRONMENT name like 'potato'
but when I define this name
index.php >
PHP Code:
define('ENVIRONMENT', 'potato');
I create the folder 'potato' on the config folder
application > config > potato > config.php
And I get this message "The application environment is not set correctly."
If I change to 'testing' or 'development' it works ok.
It's not allowed to create custom development names?
Thanks.
↧
↧
A PHP Error was encountered - Message: Undefined index: title
Hello Guys, could someone give a Light please, what i am doing wrong here?
Thanks in Advance!
This is my Post Controller:
and this the view file:
and this is the error message on the browser:
A PHP Error was encountered
Line: 315
Function: require_once
Thanks in Advance!
This is my Post Controller:
Code:
// LOAD POST INDIVIDUALLY
public function view ($slug = NULL)
{
//******* THE FUNCTIONS MUST BE LOADED IN EVERY METHOD *******//
// Load the Function php echo base_url();
$this->load->helper('url');
// Loading a Model Locally
$this->load->model('Post_model');
//******* THE FUNCTIONS MUST BE LOADED IN EVERY METHOD *******//
$data['post'] = $this->Post_model->get_posts($slug);
if(empty($data['post']))
{
show_404();
}
$data['title'] = $data['post']['title'];
$this->load->view('templates/header');
$this->load->view('posts/view', $data);
$this->load->view('templates/footer');
}and this the view file:
Code:
<h2><?php echo $post['posts_title']; ?></h2>
<small class="post-date">Posted on:
<?php echo $post['posts_date_insertion']; ?>
</small><br>
<div class="post-body">
<?php echo $post['posts_body']; ?>
</div>and this is the error message on the browser:
A PHP Error was encountered
Severity: Notice
Message: Undefined index: title
Filename: controllers/Posts.php
Line Number: 59
Backtrace:
File: C:\xampp\htdocs\dogs\application\controllers\Posts.php
Line: 59
Function: _error_handler
File: C:\xampp\htdocs\dogs\index.phpLine: 59
Function: _error_handler
Line: 315
Function: require_once
↧
Need a variable (VARCHAR) returned from a selection
I want a variable output, out of a selection in a pull down menu.
Below is the code for selection & it works for selection. But, it is not returning anything.
<tr>
<td>Consideration</td>
<td>
<select $name="basis">
<option value="">--Select--</option>
<option value="abc">ABC</option>
<option value="pqr">PQR</option>
<option value="xyz">XYZ</option>
</select>
</td>
</tr>
echo $name
I get error. Notice: Undefined variable: name in C:\xampp\htdocs\Practice\misc\test1.php on line xx
( I am using above in a CodeIgniter based application in the middle of a another code but I am stuck up)
Kindly help with a suitable solution.
Below is the code for selection & it works for selection. But, it is not returning anything.
<tr>
<td>Consideration</td>
<td>
<select $name="basis">
<option value="">--Select--</option>
<option value="abc">ABC</option>
<option value="pqr">PQR</option>
<option value="xyz">XYZ</option>
</select>
</td>
</tr>
echo $name
I get error. Notice: Undefined variable: name in C:\xampp\htdocs\Practice\misc\test1.php on line xx
( I am using above in a CodeIgniter based application in the middle of a another code but I am stuck up)
Kindly help with a suitable solution.
↧
Issue - Form_Validation > Setting Error Messages > set_rule()
Hi Guys,
Could someone please give a Light what's going wrong here please?
I try to set a custom error message for a particular field on some particular rule, but when i call the rule, i still see the native error messages from the file system/language/english/form_validation_lang.php.
I've checked other Posts from another users, but i didn't find the correct answer for that. I try to do exactly what the documentation says, but till now it doesn't work.
Documentation:
https://www.codeigniter.com/userguide3/l...r-messages
"If you need to set a custom error message for a particular field on some particular rule, use the set_rules() method:"
This is my Post Method.
And this is my view Form file
I thank you in Advance for any Help or Light.
Could someone please give a Light what's going wrong here please?
I try to set a custom error message for a particular field on some particular rule, but when i call the rule, i still see the native error messages from the file system/language/english/form_validation_lang.php.
I've checked other Posts from another users, but i didn't find the correct answer for that. I try to do exactly what the documentation says, but till now it doesn't work.
Documentation:
https://www.codeigniter.com/userguide3/l...r-messages
"If you need to set a custom error message for a particular field on some particular rule, use the set_rules() method:"
Code:
$this->form_validation->set_rules('field_name', 'Field Label', 'rule1|rule2|rule3', array('rule2' => 'Error Message on rule2 for this field_name'));This is my Post Method.
Code:
// CREATE NEW POST FORM
public function create()
{
//******* THE FUNCTIONS MUST BE LOADED IN EVERY METHOD *******//
// Load the Function php echo base_url();
$this->load->helper('url');
// Loading a Model Locally
$this->load->model('Post_model');
// Loading a Form Helper Locally
// Load the Function php echo base_url();
$this->load->helper(array('form', 'url'));
// Loading Form Validation Library Locally
$this->load->library('form_validation');
//******* THE FUNCTIONS MUST BE LOADED IN EVERY METHOD *******//
$data['title'] = 'Create Post';
$this->form_validation->set_rules('title', 'Post Title', 'trim|min_length[5]|max_length[85]|required', array('required' => 'O campo Título deve ter minimo 5 caracteres.'));
$this->form_validation->set_rules('body', 'Body', 'trim|required|min_length[5]|max_length[1000]');
// IF THE LIBRARY "FORM VALIDATION" RECOGNIZE THAT ONE
// OF THE RULES IS NOT RESPECTED THEN STAY ON http://localhost/dogs/posts/create
if ($this->form_validation->run() === FALSE)
{
$this->load->view('templates/header');
$this->load->view('posts/create', $data);
$this->load->view('templates/footer');
} else {
// ELSE...EXECUTE THE POST_MODEL METHOD create_post & REDIRECT TO http://localhost/dogs/posts
$this->Post_model->create_post();
// REDIRECT TO http://localhost/dogs/posts
redirect('posts');
}
}And this is my view Form file
Code:
<!-- FORMNAME -->
<h2><?= $title; ?></h2>
<!-- GENERATE FORM VALIDATION ERROR MESSAGES -->
<?php echo validation_errors(); ?>
<!-- FORM CREATEION -->
<?php echo form_open('posts/create'); ?>
<div class="form-group">
<label>Post Title</label>
<input type="text" class="form-control" id="#" aria-describedby="#" name="title" placeholder="Post Title">
<small id="emailHelp" class="form-text text-muted">We'll never share your email with anyone else.</small>
</div>
<div class="form-group">
<label>Post Content</label>
<textarea class="form-control" id="#" name="body" placeholder="Write Post Content"></textarea>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>I thank you in Advance for any Help or Light.
↧
starting a development with CI alpha.
Do you think guys CI4 is enough mature to start a project with a long time of dev. ?
Migrate from CI3 to CI4 seems to be complicated, i have to make a choice today. I start a new project (approx 18/24 months of dev...)
CI3 or CI4 ?
Migrate from CI3 to CI4 seems to be complicated, i have to make a choice today. I start a new project (approx 18/24 months of dev...)
CI3 or CI4 ?
↧
↧
system check the registered email database, and log in to the related DB
Hello, how do I make the following change in codeigniter, it's possible?
when logging into the system check the registered email database, and log in to the related database, for example:
User: teste@teste.com
Database: xyz
User: teste2@teste.com
database: abc
after login, this will be the user session database.
I tried in many bad ways it does not work
my function of verification email x database
my database.php
trying to set the database when signing in
when logging into the system check the registered email database, and log in to the related database, for example:
User: teste@teste.com
Database: xyz
User: teste2@teste.com
database: abc
after login, this will be the user session database.
I tried in many bad ways it does not work
my function of verification email x database
Code:
function get_base_email($email)
{
$CI = & get_instance();
$CI->db->where('email', $email);
return $CI->db->get('tblusuariobanco')->row()->banco;
}my database.php
Code:
$db['xyz'] = [
'dsn' => '', // Not Supported
'hostname' => APP_DB_HOSTNAME,
'username' => APP_DB_USERNAME,
'password' => APP_DB_PASSWORD,
'database' => 'gestor',
'dbdriver' => defined('APP_DB_DRIVER') ? APP_DB_DRIVER : 'mysqli',
'dbprefix' => '', // Not Supported
'pconnect' => false,
'db_debug' => (ENVIRONMENT !== 'production'),
'cache_on' => false,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => $db_encrypt,
'compress' => false,
'stricton' => false,
'failover' => [],
'save_queries' => true,
];
$db['abc'] = [
'dsn' => '', // Not Supported
'hostname' => APP_DB_HOSTNAME,
'username' => APP_DB_USERNAME,
'password' => APP_DB_PASSWORD,
'database' => 'xxx',
'dbdriver' => defined('APP_DB_DRIVER') ? APP_DB_DRIVER : 'mysqli',
'dbprefix' => '', // Not Supported
'pconnect' => false,
'db_debug' => (ENVIRONMENT !== 'production'),
'cache_on' => false,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => $db_encrypt,
'compress' => false,
'stricton' => false,
'failover' => [],
'save_queries' => true,
];trying to set the database when signing in
Code:
$active_group = get_base_email($email);↧
Custom 404 page working in localhost, but not in live site..
Hello,
I have the following problem..
I've created a custom 404 page controller and overrided it with routes file.
But the thing is that in my localhost site this custom 404 page working fine, but in live site, the 404 error page is loaded over "application/views/errors/html/error_404.php" and not from the custom view file with header, footer etc..
Any ideas on what's going on?
Here are routes, controller files etc...
Routes:
"c404" Controller:
My_controller file:
Thanks!
I have the following problem..
I've created a custom 404 page controller and overrided it with routes file.
But the thing is that in my localhost site this custom 404 page working fine, but in live site, the 404 error page is loaded over "application/views/errors/html/error_404.php" and not from the custom view file with header, footer etc..
Any ideas on what's going on?
Here are routes, controller files etc...
Routes:
Code:
$route['404_override'] = 'c404';"c404" Controller:
Code:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class c404 extends MY_Controller {
public function __construct(){
parent::__construct();
}
public function index(){
$this->output->set_status_header('404');
$data['title'] = 'Page not found!';
$this->render_page('404', $data);
}
}My_controller file:
Code:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class MY_Controller extends CI_Controller {
protected function render_page($view, $data) {
$data['site'] = $this->page_model->get_info();
$this->load->view('templates/header', $data);
$this->load->view($view, $data);
$this->load->view('templates/footer', $data);
}
}Thanks!
↧
How save timestamp according to Asia timezone
Hi
I receive timestamp base of UTC and save it into database
Now i need report all data example between 2:30 to 14:43
And i am Tehran with GMT +3:50
Can i save timestamp base of Asia/Tehran timezone or i can only get their base of my favorite timezone?
Can i set timezone to Asia/Tehran on mysql when i use SELECT command?
Thanks
I receive timestamp base of UTC and save it into database
Now i need report all data example between 2:30 to 14:43
And i am Tehran with GMT +3:50
Can i save timestamp base of Asia/Tehran timezone or i can only get their base of my favorite timezone?
Can i set timezone to Asia/Tehran on mysql when i use SELECT command?
Thanks
↧