I am trying to generate pedigree
my DB schema:
CREATE TABLE `Pedigrees` (
`pedigrees_id` int(10) NOT NULL AUTO_INCREMENT,
`horse_name` varchar(32) NOT NULL,
`sire_id` int(10) DEFAULT NULL,
`dam_id` int(10) DEFAULT NULL,
PRIMARY KEY (`pedigrees_id`),
and other info data
Generete GII CRUD for controller model and index.php and viev.php
get info for SIRE and DAM to viev.php
Model Pedigrees:
public function getParentsir()
{
return $this->hasOne(Pedigrees::className(), ['pedigrees_id' => 'sire_id']);
}
public function getParentdam()
{
return $this->hasOne(Pedigrees::className(), ['pedigrees_id' => 'dam_id']);
}
and for viev.php use html + php ()
<?php if ($model->parentdam->parentdam->parentdam->parentdam) {
echo Html::a(Html::encode($model->parentdam->parentdam->parentdam->parentdam->name));
}else{
echo "<tr><td><li>none</li></td></tr>";
}?>
and table example:
<table>
<TR><TD ROWSPAN=8 >
<div>
<h3> <?php
echo Html::a( Html::encode($model->name, $model->pedigrees_id), Url::to(['pedigrees/view', 'id' => $model->pedigrees_id]));
echo Html::img('/web/images/photo_p/'.$model->photo_path, [ 'class'=>'img-responsive img-rounded']);;
echo "</h3>";
echo "<ul>
<li>$model->color</li>
<li>$model->land_stand</li>
<li>$model->date_birth</li>
<li>$model->titles</li>
</ul> </div> </div> </TD>";
?>
<?php if ($model->parentsir) {
echo " <TD ROWSPAN=4 >
<div class=header><h3>sir1_1 ";
echo Html::a( Html::encode($model->parentsir->name, $model->parentsir->pedigrees_id), Url::to(['pedigrees/view', 'id' => $model->parentsir->pedigrees_id]));
echo Html::img('/web/images/photo_p/'.$model->parentsir->photo_path, [ 'class'=>'img-responsive img-rounded']);
echo "<br>";
echo Html::label( $model->parentsir->color);
echo Html::label( $model->parentsir->date_birth);
echo Html::label( $model->parentsir->titles);
echo "</h3></div>
</TD>
<TD ROWSPAN=2 >
<div class=header><h3>sir1_3";
if ($model->parentsir->parentsir) {
echo Html::a( Html::encode($model->parentsir->parentsir->name, $model->parentsir->parentsir->pedigrees_id), Url::to(['pedigrees/view', 'id' => $model->parentsir->parentsir->pedigrees_id]));
echo Html::img('/web/images/'.$model->parentsir->parentsir->photo_path, ['class'=>'img-responsive img-rounded']);
echo Html::label( $model->parentsir->parentsir->color);
echo Html::label( $model->parentsir->parentsir->date_birth);
echo Html::label( $model->parentsir->parentsir->titles);
} else {
echo "no info";
}
ETC...
</table>
i have lov skill for YII2 and php
may be some have better solution for this?
or can help with this example for this solution for YII1 Remake for yii2?
Related
I'm using cakephp 1.3,I want to create a link with to params ( id and nbr) to call function in controller but the problem is I can't get the input value inside my form..
here my code:
<tr>
<td width="25%"> <?php echo $value['StocksCour']['module_formation']; ?> </td>
<td width="25%"> <?php echo $value['StocksCour']['nb_stock']; ?> </td>
<td width="25%">
<?php
echo $form->create('StocksCour');
echo $bouton->add('-', array('id'=>'subtsract', 'div'=>false));
echo $v->input('nbr_edit',array(
'id'=>'nbr_edit',
'label'=>false,
'default'=> $value['StocksCour']['nb_stock'],
'div'=>false,
'style'=>'width:30px;'
));
echo $bouton->add('+', array('id'=>'add', 'div'=>false));
echo $v->input('id_formation',array(
'type'=>'hidden',
'name'=>'id_formation',
'id'=>'id_formation',
'value'=>$value['StocksCour']['nom_formation']
));
?>
<?php
echo $v->link(
'Valider',
array(
'controller'=> 'Sessions',
'action'=>'saveChange',
$value['StocksCour']['id_formation'] ,
$this->data['StocksCour']['nbr_edit']
),
array(
'image'=>'tick.gif',
'class'=>'button small',
'post'
)
);
?>
</tr>
the problem is she have to get the new 'nb_edit' after change ..
I am attempting to create some custom widgets.
I have created one, which only needed a different title field. However I am now stuck when trying to create a widget which allows me to have multiple fields. I need the following fields for the widget:
Title
Introduction text
Main text
Email address
I want the widget form to allow the user to update the fields above with text. I then want to output the text they have written in my sidebar widget.
I have the following code which is for the previous widget I made (with no extra fields other than title)
class registercv_widget extends WP_Widget {
function __construct() {
parent::__construct(
'registercv_widget',
__('Register CV Widget', 'registercv_widget_domain'),
array( 'description' => __( 'Provides a "Register CV" button which launches a pop-up', 'registercv_widget_domain' ), )
);
}
public function widget( $args, $instance ) {
$title = apply_filters( 'widget_title', $instance['title'] );
echo $args['before_widget'];
echo '<div class="widget-wrapper">';
if ( ! empty( $title ) )
echo $args['before_title'] . $title . $args['after_title'];
// This is where you run the code and display the output
echo __( '<div class="register-button"><span><div class="button white">Send your CV</div></span></div>', 'registercv_widget_domain' );
echo '</div>';
echo $args['after_widget'];
}
// Widget Backend
public function form( $instance ) {
if ( isset( $instance[ 'title' ] ) ) {
$title = $instance[ 'title' ];
}
else {
$title = __( 'Register as a candidate', 'registercv_widget_domain' );
}
// Widget admin form
?>
<p>
<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" />
</p>
<?php
}
// Updating widget replacing old instances with new
public function update( $new_instance, $old_instance ) {
$instance = array();
$instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
return $instance;
}
}
function registercv_load_widget() {
register_widget( 'registercv_widget' );
}
add_action( 'widgets_init', 'registercv_load_widget' );
This works fine but how can I add extra fields to this?
I have attempted copying all instances of $title and making them again but with $text_one but I do not understand how this field is being registered. Can anybody help?
Found the solution.
I started with the code above and was able to create multiple fields as such:
echo $args['before_widget'];
echo '<div class="widget-wrapper">';
if ( ! empty( $title ) )
echo $args['before_title'] . $title . $args['after_title'];
if ( ! empty( $text_two ) )
echo '<p>' . $text_two . '</p>';
if ( ! empty( $link_text ) )
echo '<p>' . $link_text . '<i class="fa fa-play"></i></p>';
echo '</div>';
echo $args['after_widget'];
The above example makes use of $text_two and $link_text variables which can be set through the widget screen with use of the following:
public function form( $instance ) {
if ( isset( $instance[ 'title' ] ) ) {
$title = $instance[ 'title' ];
}
else {
$title = __( 'Executive Search', 'executive_widget_domain' );
}
if ( isset( $instance[ 'text_two' ] ) ) {
$text_two = $instance[ 'text_two' ];
}
else {
$text_two = __( 'Systematic searching to map the right talent for Director level roles using the best possible sector intelligence.', 'executive_widget_domain' );
}
if ( isset( $instance[ 'link_text' ] ) ) {
$link_text = $instance[ 'link_text' ];
}
else {
$link_text = __( 'Visit Executive Search', 'executive_widget_domain' );
}
// Widget admin form
?>
<p>
<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" />
<br /><br />
<label for="<?php echo $this->get_field_id( 'text_two' ); ?>"><?php _e( 'Main text:' ); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id( 'text_two' ); ?>" name="<?php echo $this->get_field_name( 'text_two' ); ?>" type="text" value="<?php echo esc_attr( $text_two ); ?>" />
<br /><br />
<label for="<?php echo $this->get_field_id( 'link_text' ); ?>"><?php _e( 'Link text' ); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id( 'link_text' ); ?>" name="<?php echo $this->get_field_name( 'link_text' ); ?>" type="text" value="<?php echo esc_attr( $link_text ); ?>" />
</p>
<?php
}
Entire code snippet here which can be popped right into your project. http://pastebin.com/X7wXmcds
Placing the above code in your functions.php will give you a widget called Executive Search. It has three fields:title,text_two(a simple text string) andlink text`. So those are the three fields the user can add.
I have a result.php page in view/result.php
<body>
<table border="1">
<tr>
<th>name1</th>
<th>name2</th>
<th>name3</th>
</tr>
<?php foreach($result as $row): ?>
<tr>
<td><?php echo $row->name1; ?></td>
<td><?php echo $row->name2; ?></td>
<td><?php echo $row->name3; ?></td>
</tr>
<?php endforeach; ?>
</table>
<?php echo 'Your new value is '.$name1;?>
<?php echo 'Your new value is '.$name2;?>
<?php echo 'Your new value is '.$name3;?>
</body>
html table is currently working. It retrives data from my table testing and display it. The problem is echo part in below code, it doesn't work.
<?php echo 'Your new value is '.$name1;?>
<?php echo 'Your new value is '.$name2;?>
<?php echo 'Your new value is '.$name3;?>
From the same table testing. It shows an error in the error page it shows Undefined variable name1,name2,name3
controller/example.php
<?php
class Example extends CI_Controller {
function __construct()
{
parent::__construct();
$this->load->helper('form');
$this->load->helper('url');
}
function index() {
$this->load->view('example_view');
$this->getvalue();
$this->edit_content();
}
function getvalue()
{
if ($this->input->post('submit')==true) {
$data1['name1']=$this->input->post('name1');
$data1['name2']=$this->input->post('name2');
$data1['name3']=$this->input->post('name3');
$this->load->view('result',$data1);
$this->load->model('Insert_model');
$this->Insert_model->uploaddata($data);
}
}
function edit_content()
{
$data = array();
$this->load->model('Selected_model');
$this->load->helper('url');
$data['result'] = $this->Selected_model->get_contents();
$this->load->view('result',$data);
}
}
?>
<body>
<table border="1">
<tr>
<th>name1</th>
<th>name2</th>
<th>name3</th>
</tr>
<?php if(is_array($result)){ foreach($result as $row): ?>
<tr>
<td><?php echo $row->name1; ?></td>
<td><?php echo $row->name2; ?></td>
<td><?php echo $row->name3; ?></td>
</tr>
<?php endforeach; } ?>
</table>
<?php echo 'Your new value is '.$row->name1;?>
<?php echo 'Your new value is '.$row->name2;?>
<?php echo 'Your new value is '.$row->name3;?>
If your array is like in the following format.
$info = array
(
[0] => Array
(
[name1] => a
[name2] => b
[name3] => c
)
[1] => Array
(
[name1] => aa
[name2] => bb
[name3] => cc
)
[2] => Array
(
[name1] => aaa
[name2] => bbb
[name3] => ccc
)
[3] => Array
(
[name1] => aaaa
[name2] => bbbb
[name3] => cccc
)
);
Then
<body>
<table border="1">
<tr>
<th>name1</th>
<th>name2</th>
<th>name3</th>
</tr>
<?php foreach($info as $row): ?>
<tr>
<td><?php echo $row->name1; ?></td>
<td><?php echo $row->name2; ?></td>
<td><?php echo $row->name3; ?></td>
</tr>
<?php endforeach; ?>
</table>
The above loop will give you accurate result like.
name1 name2 name3
a b c
aa bb cc
aaa bbb ccc
aaaa bbbb cccc
Now the following code will generate an error because it does not know the following
$row->name1
$row->name1
$row->name1
The reason is that these are defined in the scope of foreach loop thats why its generate error.
I am creating the following table
CREATE TABLE IF NOT EXISTS `videothek9`.`movies` (
`id` INT NOT NULL AUTO_INCREMENT,
`title` VARCHAR(45) NOT NULL,
`release_year` VARCHAR(45) NOT NULL,
`available` TINYINT(1) NOT NULL DEFAULT 1,
PRIMARY KEY (`id`))
and baking it with the cakephp bake console.
Here is an example for the standard movies/index page:
The "available" field can be 0 or 1. Now i want to show specific images instead of 0 or 1, like a checkmark tick or a red x-mark. The cakephp cookbook (html helper section) didnt help me much...
And here a piece of the view code
<?php foreach ($movies as $movie): ?>
<tr>
<td><?php echo h($movie['Movie']['id']); ?> </td>
<td><?php echo h($movie['Movie']['title']); ?> </td>
<td><?php echo h($movie['Movie']['release_year']); ?> </td>
<td><?php echo h($movie['Movie']['available']); ?> </td>
<td class="actions">
<?php echo $this->Html->link(__('View'), array('action' => 'view', $movie['Movie']['id'])); ?>
<?php echo $this->Html->link(__('Edit'), array('action' => 'edit', $movie['Movie']['id'])); ?>
<?php echo $this->Form->postLink(__('Delete'), array('action' => 'delete', $movie['Movie']['id']), array(), __('Are you sure you want to delete # %s?', $movie['Movie']['id'])); ?>
</td>
</tr>
<?php endforeach; ?>
Can I just place a normal php if/else statement in the Movies Controller ?
It's pretty simple. Instead of echoing the value of "available" field use HtmlHelper::image() to echo img tag with image of your choice.
Super simple.. just do it with the if else statement.and display image or anything you want
If (0)
echo $this->Html->image('tick.png');
Else
echo $this->Html->image('cross.png');
Hey guys we have a perfectly working web page (index_admin) of the Relationships controller, but after adding pagination its all crashing.
Coming up with:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'Relationship.sender_id' in 'where clause'
Customers and businesses build 'relationships' so they can exchange invoices over our website. Here is the DB schema:
id, sender_id, receiver_id, active, requested, expiry_date
Sender_id and receiver_id are both foreign keys to the Account Table. So in other words tells the db which accounts are linked to each other.
Relationship model 'BELONGSTO' 'RECEIVER AND SENDER ACCOUNT MODELS':
public $belongsTo = array(
'ReceiverAccount' =>array(
'className' => 'Account',
'foreignKey' =>'receiver_id',
'associationForeignKey' => 'accounts_id',
),
'SenderAccount' =>array(
'className' => 'Account',
'foreignKey' =>'sender_id',
'associationForeignKey' => 'accounts_id',)
);
Index_admin:
public function index_admin(){
$this->set('title_for_layout', 'Relationships');
$this->set('stylesheet_used', 'homestyle');
$this->set('image_used', 'eBOXLogoHome.png');
$this->layout='home_layout';
//retrieve Account Id of current User
$accountid=$this->Auth->user('account_id');
//Conditions
$conditions=array(
"OR"=> array(
'Relationship.sender_id' => $accountid,
'Relationship.receiver_id' => $accountid)
);
//Find all Invoices where receiver_id = accountid
$relationships=$this->Relationship->find('all', array(
'conditions' => $conditions));
debug($conditions);
$compName = $this->Account->field('account_name', array('id' => 'Relationship.id'));
$this->paginate = array(
'limit' => 10,
'conditions'=> $conditions
);
$this->set('accountid', $accountid);
$this->set('relationship', $this->paginate());
$this->set('compName', $compName);
}
Index_admin view (partial):
<table id="data">
<tr>
<td colspan=7 align='right'>
<?php
echo $this->Paginator->prev('<' . __('previous'), array(), null, array('class'=>'prev disabled'));
echo ' ';
echo $this->Paginator->numbers(array('seperator'=>''));
echo ' ';
echo $this->Paginator->next(__('next') . '>', array(), null, array('class'=>'next disabled'));
?>
</td>
</tr>
<tr>
<th><?php echo $this->Paginator->sort('id'); ?></th>
<th><?php echo $this->Paginator->sort('sender_id'); ?></th>
<th><?php echo $this->Paginator->sort('receiver_id'); ?></th>
<th><?php echo $this->Paginator->sort('expiry_date'); ?></th>
<th>Status</th>
<th>Actions</th>
</tr>
<?php foreach($relationship as $relationships):?>
<?php
if($relationships['Relationship']['requested']==1)
{
$status = 'Requested';
$bgcol = '#F8FAC0';
}
else if($relationships['Relationship']['active']==1)
{
$status = 'Active';
$bgcol = '#CFDAE8';
}
else if($relationships['Relationship']['active']==0)
{
$status = 'Expired';
$bgcol = '#FAB9B9';
}
if($relationships['Relationship']['active']==0 && $relationships['Relationship']['requested']==0)
{
$action = 'Reactivate';
}
else
{
$action = 'Edit Expiry';
}
if($relationships['Relationship']['sender_id']==$accountid)
{
$start = '<font color="#191970">';
$end = '</font>';
}
else
{
$start = NULL;
$end = NULL;
}
if($relationships['Relationship']['receiver_id']==$accountid)
{
$startr = '<font color="#191970">';
$endr = '</font>';
}
else
{
$startr = NULL;
$endr = NULL;
}
if($relationships['Relationship']['sender_id']==$accountid)
{
$acctname = $relationships['ReceiverAccount']['account_name'];
}
else if($relationships['Relationship']['receiver_id']==$accountid)
{
$acctname = $relationships['SenderAccount']['account_name'];
}
?>
<tr>
<td align='center'><?php echo $relationships['Relationship']['id']; ?></td>
<td align='center'><?php echo $start?><?php echo $relationships['SenderAccount']['account_name']; ?><?php echo $end ?></td>
<td align='center'><?php echo $startr?><?php echo $relationships['ReceiverAccount']['account_name']; ?><?php echo $endr ?></td>
<td align='center'><?php echo date('d.m.Y', strtotime($relationships['Relationship']['expiry_date'])); ?></td>
<td align='center' bgcolor='<?php echo $bgcol ?>'><?php echo $status ?></td>
<td align='center'>
<?php echo $this->Form->Html->link('Delete', array('controller' => 'Relationships','action'=>'delete',$relationships['Relationship']['id']), NULL, 'Are you sure you want to delete '. $acctname);
?> | <?php echo $action ?> </td>
</tr>
<?php endforeach; ?>
<tr>
<td colspan=7 align='right'>
<?php
echo $this->Paginator->prev('<' . __('previous'), array(), null, array('class'=>'prev disabled'));
echo ' ';
echo $this->Paginator->numbers(array('seperator'=>''));
echo ' ';
echo $this->Paginator->next(__('next') . '>', array(), null, array('class'=>'next disabled'));
?>
</td>
</tr>
</table>
Like I said it was all working before hand, now it isn't, but I can't see why.
It is always wise to set the debug mode on to see all possible errors in detail. You've just shared the sql error part from which it is clear that the intended table doesn't have the "sender_id" field. I'm assuming you've debug mode on. So first have a look at the generated query. Then you'll find which table the query is trying to dig in.
If your query is referencing the correct table, you can try this:
public function index_admin(){
$this->set('title_for_layout', 'Relationships');
$this->set('stylesheet_used', 'homestyle');
$this->set('image_used', 'eBOXLogoHome.png');
$this->layout='home_layout';
//retrieve Account Id of current User
$accountid=$this->Auth->user('account_id');
//Conditions
$conditions=array(
"OR"=> array(
'Relationship.sender_id' => $accountid,
'Relationship.receiver_id' => $accountid)
);
App::import('Model', 'Relationship');
$objRelationship = new Relationship();
$this->paginate = array( "conditions" => $conditions, 'limit' => 10 );
$relationships = $this->paginate( $objRelationship );
$compName = $this->Account->field('account_name', array('id' => 'Relationship.id'));
$this->set('accountid', $accountid);
$this->set('relationship', $this->paginate());
$this->set('compName', $compName);
}