/var/www/page/page/video.php:
<?php
class page_video extends Page {
function init(){`enter code here`
parent::init();
$form=$this->add('Form');
$d=$this->add('Tabs');
$d->addTab('klienci_w')->add('CRUD')->setModel('KlienciW');
if($form->isSubmitted()){
$form->js()->execute();
}
}
}
/var/www/page/lib/Model/KlienciW.php
<?php
class Model_KlienciW extends Model_Table {
public $entity_code='klienci_w';
public $debug=true;
function init(){
parent::init();
$this->addField('adresid');
$this->addField('adresn');
$this->addField('adresu');
$this->addField('adresk');
$this->addField('adresp');
$this->addField('aosoba');
$this->addField('aosobat');
$this->addField('odbiorcaid');
$this->addField('data')->type('date');
$this->addField('datau')->type('date');
}
}
I have an answer form Chrome (in Firefox is the same):
insert into `klienci_w` (`adresid`,`adresn`,`adresu`,`adresk`,`adresp`,`aosoba`,`aosobat`,`odbiorcaid`,`data`,`datau`) values ("sdfsd","fsdf","sdfsd","fsdf","sdfsd","fsdfsd","fsdf","sdf","2012-05-16","2012-05-18") [:a_10, :a_9, :a_8, :a_7, :a_6, :a_5, :a_4, :a_3, :a_2, :a]
select `id`,`adresid`,`adresn`,`adresu`,`adresk`,`adresp`,`aosoba`,`aosobat`,`odbiorcaid`,`data`,`datau` from `klienci_w` where `id` = "6" limit 0, 1 [:a]
$('#Frontend_video_tabs_view_htmlelement_crud').trigger('reload');$('#Frontend_video_tabs_view_htmlelement_crud_form').univ().closeDialog()
In MySQL this data was added to the DB, but the Form is still on primary screen in web browser, on PostgreSQL nothing happend, but the Form is still on primary screen in web browser.
ATK4 in version 4.2 and 4.2.1.
What am I doing wrong?
Turn debug off by removing debug=true line.
Related
I have following code in my php class called Plaint:
class Plaint extends CAction
{
public function run()
{
$model = new PlaintForm();
$this->runTests($model);
...........
I need to run this class without($this->runTests($model)), if enter from this url /plaint. If I enter this page from other url, I need to run $this->runTests($model);.(e.g /filled). How can I do it?
You can look for specific phrase in current url:
if(strpos(Yii::app()->request->requestUri, '/filled') !== false) {
$this->runTests($model);
}
I advise against putting test code into production code.
I am trying to test around Agile Toolkit with oracle, after seting up a model and trying to show a grid it says "No records found"...
Let me tell you what I did, since i've been guessing most of all configuration as I found no guides for oracle.
My Oracle connection string in agiletoolkit config-default.php file looks like this:
$config['dsn']= array( 'oci:dbname=localhost/MYDATABASE', 'MYUSER', 'MYPASSWORD' );
To fix the driver not found error, I enabled extension=php_pdo_oci8.dll in the php.ini file from my apache installation.
Then there was an error about a missing "oci.php", to solve that I had to create my own file like this:
class DB_dsql_oci extends DB_dsql {
function limit($cnt,$shift=0){
$cnt+=$shift;
$this->where('NUM_ROWS>=',$shift);
$this->where('NUM_ROWS<',$cnt);
return $this;
}
function render_limit(){
return '';
}
}
and placed it at: ...atk4\lib\DB\dsql
To fix the special chars error from oracle , I set line 59 on /atk4/lib/DB/dsql.php to empty string like this: public $bt='';
I manage to run the database test, and it says "Successfully connected to database."
Then I created a model "lib\Model\Mytable.php" like this:
<?php
class Model_Mytable extends Model_Table {
public $table = "MYTABLE";
function init(){
parent::init();
$this->addField('ID');
$this->addField('NAME');
$this->addField('INIDATE');
$this->addField('ENDDATE');
}
?>
After that, I made a new page and tried to use the model like this:
<?php
class page_test extends Page {
function init(){
parent::init();
$form = $this->add('Grid');
$form->setModel('Mytable');
}
}
?>
After refreshing the browser, it will show the grid saying " No Records found"
I wonder whats happening, that table has records no doubt, all data is committed, and im sure oracle is parsing queries because if I miss a column name an oracle error will raise.
Any clue?
This is how you can simply set DSQL as your View (Grid for example) data source:
class page_test extends Page_Basic
{
function init()
{
parent::init();
// DSQL
$q = $this->api->db->dsql();
$q->table('MYTABLE')
->field('DNAME')
->field('INIDATE');
// Create grid and set DSQL as its data source
$g = $this->add('Grid');
$g->addColumn('DNAME');
$g->addColumn('INIDATE');
$g->setSource($q);
// better add paginator too or your grid can become huge :)
$g->addPaginator();
}
}
I'm learning PHPUNIT at the moment. It was getting interesting until i got stuck on something.
I "logged-in" it and went well,
But this PrintOut just displays. Is there anyway I could remove it?
Actually I just want to get the value of the Surname, FirstName and the the picture most importantly, the picture.
The picture is saved as /ImagePage.aspx. Is there a way in which I can download this and force close the browser because I don't know how to close the print Pop-out
The picture frame id is CandImg
This is my code:
<?php
class TestLogin extends PHPUnit_Extensions_Selenium2TestCase
{
public function setUp()
{
$this->setHost('localhost');
$this->setPort(4444);
$this->setBrowser('firefox');
$this->setBrowserUrl('http://localhost/tutor');
}
public function setSpeed($timeInMilliSec)
{
$this->setSpeed('120');
}
/*Function to locate website*/
public function testHasLoginForm()
{
$this->url('http://www.jamb.org.ng/DirectEntry/');/*This is the site*/
$username = $this->byId('ctl00_ContentPlaceHolder1_RegNumber');/*Search for a name*/
$this->assertContains('Reg.Number/PIN', $username->value());
##ctl00_ContentPlaceHolder1_txtRegNumber
$action = $this->byName('ctl00$ContentPlaceHolder1$Reprint')->attribute('action');
$this->byId('ctl00_ContentPlaceHolder1_RegNumber')->value('49003257DE');/*value of the textbox*/
$jump = $this->byName('ctl00$ContentPlaceHolder1$Reprint');
$this->byName('ctl00$ContentPlaceHolder1$Reprint')->click();
}
}
#to Save ImagePage.aspx
?>
I hope someone can help me with this one before I jump off the window. I spent few hours on this one and don't know what am I doing wrong.
Basically, I've installed HMVC in CodeIgniter 2.1.2 and everything works fine, BUT for some reason I can't load models the same way I'm doing it in standard controllers. In the old codeigniter 1.7.1 I could use it simply by invoking $this->load->model('my_model') but now I can't?!
Every single time I'm trying to load model I get this error:
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Special_cart::$db
Filename: core/Model.php
Line Number: 51
I have had installed it step-by-step according to the instructions. I got third_party next to modules folder. In modules I have few modules stored like this:
modules
--boxes
----controller
----models
----views
I invoke module in my code like this:
<?=modules::run('boxes/special_cart/index');?>
My module controller code looks like this:
class Special_cart extends CI_Controller
{
public function __construct()
{
parent::__construct();
}
public function index()
{
if ($this->session->userdata('cart'))
{
# get product id's and each quantity
$cart_product_list = array_count_values($this->session->userdata('cart'));
# get list of product_id
$product_list = array_keys($cart_product_list);
# get product details
$this->load->model('productmodel');
$this->load->model('stockmodel');
$cart_products = $this->productmodel->cart_get_products_details($product_list);
$final_cart_array = array();
foreach($cart_products as $cart_product){
$product_stock = $this->stockmodel->view_product_stock($cart_product["id"]);
if(empty($product_stock) || $product_stock["UNITS"]<=0)
$cart_product["UNITS"] = 0;
else{
if($cart_product_list[$cart_product["id_web"]]>$product_stock["UNITS"])
$cart_product["UNITS"] = $product_stock["UNITS"];
else{
$cart_product["UNITS"] = $cart_product_list[$cart_product["id_web"]];
}
}
$final_cart_array[] = $cart_product;
}
$refresh_cart_array = array();
foreach($final_cart_array as $cart_product){
for($i=1;$i<=$cart_product["UNITS"];$i++){
$refresh_cart_array[] = $cart_product["id_web"];
}
}
$this->load->view("special_cart",array(
'refresh_cart_array' => $refresh_cart_array,
'final_cart_array' => $final_cart_array
));
} else {
$this->load->view("special_cart",array(
'refresh_cart_array' => NULL,
'final_cart_array' => NULL
));
}
}
}
I've tried every possible solution found on internet - none of them work....
I hope you understand my problem but in case you need some further explanation please ask me. Can anyone help?
Looks like the model you're trying to load wants to connect to the db, but the database driver is not available. If you use database queries in your application, why don't you load the database driver automatically?
Just insert "database" in the "libraries" array in application/config/autoload.php file. Don't forget to insert your database credentials into application/config/database.php.
$autoload['libraries'] = array('database');
If you need database connection just in one single model, load it before trying to access database library.
$this->load->database();
Try loading the model stating the module name as follows
$this->load->model('module_name/productmodel');
Class Models extends MX_Loader{
function getUser($username){
$sql="SELECT * FROM user WHERE username = ? ";
return $this->db->query($sql,array($username))->row();
}
}
you must using extends MX_Loader because i don't know if using CI_Model the database core cant be load in Codeigniter,,,
Try to use extend MX_Controller class (not CI_Contoller like you are doing atm)
Based on what you have wrote in comment above, I figured that you tried to create new instance of DB in module (based on chrises comment).
Do it on constuctor of Special_cart
So update current construct to be like
public function __construct()
{
parent::__construct();
$this->load->database('default');
}
(I'm writing this from top of my head, so check the methods)
Now for sure db driver should be available in your models.
Regarding issue with HMVC I dont think there are any. I'm using HMVC for a while now, and I found no problems in it (working with databases)
I had the same problem and mistake. I missed to extend controllers to MX_Controller. So the solution would be to change CI_Controller to MX_Controller like this:
class Special_cart extends MX_Controller
{
public function __construct()
{
parent::__construct();
$this->load->model('productmodel');
$this->load->model('stockmodel');
}
public function index()
{
if ($this->session->userdata('cart'))
{
# get product id's and each quantity
$cart_product_list = array_count_values($this->session->userdata('cart'));
# get list of product_id
$product_list = array_keys($cart_product_list);
# get product details
$cart_products = $this->productmodel->cart_get_products_details($product_list);
$final_cart_array = array();
foreach($cart_products as $cart_product){
$product_stock = $this->stockmodel->view_product_stock($cart_product["id"]);
if(empty($product_stock) || $product_stock["UNITS"]<=0)
$cart_product["UNITS"] = 0;
else{
if($cart_product_list[$cart_product["id_web"]]>$product_stock["UNITS"])
$cart_product["UNITS"] = $product_stock["UNITS"];
else{
$cart_product["UNITS"] = $cart_product_list[$cart_product["id_web"]];
}
}
$final_cart_array[] = $cart_product;
}
$refresh_cart_array = array();
foreach($final_cart_array as $cart_product){
for($i=1;$i<=$cart_product["UNITS"];$i++){
$refresh_cart_array[] = $cart_product["id_web"];
}
}
$this->load->view("special_cart",array(
'refresh_cart_array' => $refresh_cart_array,
'final_cart_array' => $final_cart_array
));
} else {
$this->load->view("special_cart",array(
'refresh_cart_array' => NULL,
'final_cart_array' => NULL
));
}
}
}
this is also explained in the documentation
https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc/
, here the quote:
Notes:
To use HMVC functionality, such as Modules::run(), controllers must
extend the MX_Controller class. To use Modular Separation only,
without HMVC, controllers will extend the CodeIgniter Controller
class. You must use PHP5 style constructors in your controllers. ie:
<?php
class Xyz extends MX_Controller
{
function __construct()
{
parent::__construct();
}
}
My crazy designer would like the message "Required" displaying (in red) inside a field if the form has been submitted and it is invalid because of an empty field.
The form in question is a login prompt and I'm using a custom class that extends sfGuardFormSignin
I've managed to set the value and add a class with..
$this->widgetSchema['username']->setAttribute('class','red');
$this->widgetSchema['username']->setDefault('Required');
..but how do I do this only when the username field is invalid and because of the Required error?
I assume it's the same for the password field?
Many thanks in advance
EDIT:
Thanks for the advice greg0ire. I've had a play with that but the formatRow method of sfWidgetFormSchemaFormatter doesn't seem to be getting hit. Is this because my form extends sfGuardFormSignin and using the sfGuardAuth plugin?
class FrontendsfGuardFormSignin extends sfGuardFormSignin
{
public function configure()
{
parent::configure();
// This works!
$this->widgetSchema['username']->setLabel('Email');
// I copied this from the link you pasted
$decorator = new myWidgetFormSchemaFormatterCustom($this->getWidgetSchema());
$this->widgetSchema->addFormFormatter('custom', $decorator);
$this->widgetSchema->setFormFormatterName('custom');
}
}
/lib/widget/myWidgetFormSchemaFormatterCustom.class.php
class myWidgetFormSchemaFormatterCustom extends sfWidgetFormSchemaFormatter
{
public function __construct(sfWidgetFormSchema $widgetSchema)
{
parent::__construct($widgetSchema);
}
public function formatRow($label, $field, $errors = array(), $help = '', $hiddenFields = null)
{
// Nothing happens!?
var_dump($errors);
die();
parent::formatRow($label, $field, $errors, $help, $hiddenFields);
}
}
$widget->render(array('value' => $widget->getError()));
Designers have such crazy ideas...
You'll have to write a custom schema formatter to do this. You'll probably have to override the formatRow() method to achieve this.
Analyse the $errors array argument of this method, and if you spot the "Required" error in it, then do your special stuff. You won't need to use the code you posted in your question.