How can i fix illegal offset type - codeigniter-3

I'm getting an error saying that I have an illegal offset in this code:
public function add_result(){
$marks= $this->input->post('marks');
print_r($marks);
$subject= $this->input->post('subject');
print_r($subject);
$st_roll= $this->input->post('st_roll');
print_r($st_roll);
$marks= array($st_roll => array( $subject => $marks));
foreach($marks as $key => $value){
foreach($value as $sub => $value1)
{
echo "{$key} - {$sub} - {$value1} <br>";
}
}
}
(illegal offset warning in this line)
$marks= array($st_roll => array( $subject => $marks));

public function add_result(){
$marks= "demo10";
$subject= "markss";
$st_roll= "rollno15";
$marks = array($st_roll => array( $subject => $marks));
echo "<pre>";
print_r($marks);
echo "</pre>";
foreach($marks as $key => $value)
{
foreach($value as $sub => $value1)
{
echo "{$key} - {$sub} - {$value1} <br>";
}
}
}
https://i.stack.imgur.com/KAgEC.png

Related

Send email to all the rows from mysql in codeigniter

i need to send emails to all the rows in database table with their corresponsing data. i am able to send single emails by their id, but now i need to send in bulk. i have done in pure php but in codeigniter not able to figure out. how to do this.
my controller is
public function autoformcomplete()
{
$this->load->model('admin/Reminder_model');
$datan = $this->Reminder_model->autoformemail();
//this should be in whileloop, that i am not able to figure out
$email = $datan[0]['email'];
$config = array(
'protocol' => 'smtp',
'smtp_host' => 'email-smtp.eu-west-1.amazonaws.com',
'smtp_port' => 587,
'smtp_crypto' => 'tls',
'smtp_user' => 'user',
'smtp_pass' => 'pass',
'mailtype' => 'text',
'charset' => 'utf-8',
);
$this->email->initialize($config);
$this->email->set_mailtype("html");
$this->email->set_newline("\r\n");
$this->email->set_crlf("\r\n");
$subject = "Complete Your Partially Filled Application-".$appid."";
$data['datan'] = $datan;
$mesg = $this->load->view('email/reminder/form_complete',$data,true);
$this->email->to($email);
$this->email->from('mail#mail.com','My Company');
$this->email->subject($subject);
$this->email->message($mesg);
$this->email->send();
echo "sent";
}
My Model is
public function autoformemail(){
$this->db->order_by('id', 'DESC');
$query = $this->db->get('appstbldata');
return $query->result_array();
}
Just use a foreach loop
public function autoformcomplete() {
$this->load->model( 'admin/Reminder_model' );
$datan = $this->Reminder_model->autoformemail();
foreach ( $datan as $index => $val ) {
// $val now references the current pointer to an element in your $datan array
$email = $val['email'];
$config = array(
'protocol' => 'smtp',
'smtp_host' => 'email-smtp.eu-west-1.amazonaws.com',
'smtp_port' => 587,
'smtp_crypto' => 'tls',
'smtp_user' => 'user',
'smtp_pass' => 'pass',
'mailtype' => 'text',
'charset' => 'utf-8',
);
$this->email->initialize( $config );
$this->email->set_mailtype( "html" );
$this->email->set_newline( "\r\n" );
$this->email->set_crlf( "\r\n" );
$subject = "Complete Your Partially Filled Application-" . $appid . "";
$data['datan'] = $datan;
$mesg = $this->load->view( 'email/reminder/form_complete', $data, true );
$this->email->to( $email );
$this->email->from( 'mail#mail.com', 'My Company' );
$this->email->subject( $subject );
$this->email->message( $mesg );
$this->email->send();
echo "sent";
}
}
I dunno what your point of $data['datan'] = $datan; line is though

Paragraph breaks missing from shortcode output

I created a shortcode in Wordpress to perform a query and display the content, but the content line breaks are being removed.
add_shortcode( 'resource' , 'Resource' );
function Resource($atts) {
$atts = shortcode_atts( array(
'category' => ''
), $atts );
$categories = explode(',' , $atts['category']);
$args = array(
'post_type' => 'resource',
'post_status' => 'publish',
'orderby' => 'title',
'order' => 'ASC',
'posts_per_page'=> -1,
'tax_query' => array( array(
'taxonomy' => 'category',
'field' => 'term_id',
'operator' => 'AND',
'terms' => $categories
) )
);
$string = '';
$query = new WP_Query( $args );
if( ! $query->have_posts() ) {
$string .= '<p>no listings at this time...</p>';
}
while( $query->have_posts() ){
$query->the_post();
$string .= '<div id="links"><div id="linksImage">' . get_the_post_thumbnail() . '</div>
<div id="linksDetails"><h1>'. get_the_title() .'</h1><p>' . get_the_content() . '</p>
<p>for more information CLICK HERE</div></div>';
}
wp_reset_postdata();
$output = '<div id="linksWrapper">' . $string . '</div>';
return $output;
}
Any suggestion on why this is happening and what to do to fix it. This is only happening on the shortcode output. On regular pages - the content displays correctly.
found a solution through more searches:
function get_the_content_with_formatting ($more_link_text = '(more...)', $stripteaser = 0, $more_file = '') {
$content = get_the_content($more_link_text, $stripteaser, $more_file);
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
return $content;
}
works perfect, so I thought I would share..

bootstrap mail form $from<$email> $fromEmail

I refer to this page. https://bootstrapious.com/p/how-to-build-a-working-bootstrap-contact-form and i uesd index-2.html / contact-2.php files.
i want mailheader ''
but code is
**$fromEmail = 'demo#domain.com';
$fromName = 'Demo contact form';**
$sendToEmail = 'my#mail.com';
$fields = array('name' => 'Name', 'phone' => 'Phone', 'email' => 'Email', "\r\n" , 'message' => 'Message');
so i changed
$fromEmail = "$email" $fromName = '$name'; or
$fromEmail = $_POST['form_email']; $name = $_POST['name'];
but It just makes an error.
ex) Root User" '
try
{
if(count($_POST) == 0) throw new \Exception('Form is empty');
$emailTextHtml .= "<table>";
foreach ($_POST as $key => $value) {
// If the field exists in the $fields array, include it in the email
if (isset($fields[$key])) {
$emailTextHtml .= "<tr><th>$fields[$key]</th><td>$value</td></tr>";
}
}
$emailTextHtml .= "</table>";
$mail = new PHPMailer;
$mail->setFrom($fromEmail, $fromName);
$mail->addAddress($sendToEmail, $sendToName); // you can add more addresses by simply adding another line with $mail->addAddress();
$mail->addReplyTo($from);
$mail->isHTML(true);
$mail->Subject = $subject;
$mail->msgHTML($emailTextHtml); //
what should I do?
$fromEmail = 'demo#domain.com';
$fromName = 'Demo contact form'
How should I change it?

register View-Helper understanding issue

I tried to register a View Helper for navigation, it is an example from olegkrivtsov,I chose this to learn more about the topic. I also read the posts about it. I thought it must be really easy, but it doesn't work, probably some more experienced Zend-developer will see the problem immediately.
First the folder I use, is this the right folder, what is the diffenrence to the folder helpers in the module Import for example?
Here is the content of menu.php
<?php
namespace Application\View\Helper;
use Zend\View\Helper\AbstractHelper;
// This view helper class displays a menu bar.
class Menu extends AbstractHelper
{
// Menu items array.
protected $items = [];
// Active item's ID.
protected $activeItemId = '';
// Constructor.
public function __construct($items=[])
{
$this->items = $items;
}
// Sets menu items.
public function setItems($items)
{
$this->items = $items;
}
// Sets ID of the active items.
public function setActiveItemId($activeItemId)
{
$this->activeItemId = $activeItemId;
}
// Renders the menu.
public function render()
{
if (count($this->items)==0)
return ''; // Do nothing if there are no items.
$result = '<nav class="navbar navbar-default" role="navigation">';
$result .= '<div class="navbar-header">';
$result .= '<button type="button" class="navbar-toggle" ';
$result .= 'data-toggle="collapse" data-target=".navbar-ex1-collapse">';
$result .= '<span class="sr-only">Toggle navigation</span>';
$result .= '<span class="icon-bar"></span>';
$result .= '<span class="icon-bar"></span>';
$result .= '<span class="icon-bar"></span>';
$result .= '</button>';
$result .= '</div>';
$result .= '<div class="collapse navbar-collapse navbar-ex1-collapse">';
$result .= '<ul class="nav navbar-nav">';
// Render items
foreach ($this->items as $item) {
$result .= $this->renderItem($item);
}
$result .= '</ul>';
$result .= '</div>';
$result .= '</nav>';
return $result;
}
// Renders an item.
protected function renderItem($item)
{
$id = isset($item['id']) ? $item['id'] : '';
$isActive = ($id==$this->activeItemId);
$label = isset($item['label']) ? $item['label'] : '';
$result = '';
if(isset($item['dropdown'])) {
$dropdownItems = $item['dropdown'];
$result .= '<li class="dropdown ' . ($isActive?'active':'') . '">';
$result .= '<a href="#" class="dropdown-toggle" data-toggle="dropdown">';
$result .= $label . ' <b class="caret"></b>';
$result .= '</a>';
$result .= '<ul class="dropdown-menu">';
foreach ($dropdownItems as $item) {
$link = isset($item['link']) ? $item['link'] : '#';
$label = isset($item['label']) ? $item['label'] : '';
$result .= '<li>';
$result .= ''.$label.'';
$result .= '</li>';
}
$result .= '</ul>';
$result .= '</a>';
$result .= '</li>';
} else {
$link = isset($item['link']) ? $item['link'] : '#';
$result .= $isActive?'<li class="active">':'<li>';
$result .= ''.$label.'';
$result .= '</li>';
}
return $result;
}
}
I posted the hole example for somebody who also wants to use it.
Here how I tried to register in my module.config.php
'view_helpers' => [
'factories' => [
View\Helper\Menu::class => InvokableFactory::class,
],
'aliases' => [
'mainMenu' => View\Helper\Menu::class
]
],
I placed it in the layout.phtml
<div class="collapse navbar-collapse">
<?php
$this->mainMenu()->setItems([
[
'id' => 'home',
'label' => 'Dashboard',
'link' => $this->url('home')
],
[
'id' => 'project',
'label' => 'Project',
'link' => $this->url("project", ['action'=>'index'])
],
[
'id' => 'unit',
'label' => 'Unit',
'dropdown' => [
[
'id' => 'add',
'label' => 'add Unit',
// 'link' => $this->url('unit', ['page'=>'contents'])
'link' => $this->url('unit', ['action'=>'add'])
],
[
'id' => 'help',
'label' => 'Help',
'link' => $this->url('home')
]
]
],
]);
echo $this->mainMenu()->render();
?>
</div>
With this code I replaced the former part, which came from the skeleton:
<div class="collapse navbar-collapse">
<?= $this->navigation('navigation')
->menu()
->setMinDepth(0)
->setMaxDepth(0)
->setUlClass('nav navbar-nav') ?>
I get this error message via browser:
Fatal error: Uncaught Error: Class 'Application\view\helper\Menu' not found in C:\wamp64\www\xyz\vendor\zendframework\zend-servicemanager\src\Factory\InvokableFactory.php
I'd really love to understand this because it might be really helpful in future, so any suggestion is appreciated.
Move file Menu.php to the folder Application/src/Application/View/Helper

Why was the mail sent but not received in zend framework?

I'm new to the zend framework.
I have a code to send a mail and it's working, but the message is not received by the customer side, but it returns that the mail was sent successfully. Can you teach me how to work with zend_email?
public function sendMailStatements($qid,$emails=array()) {
require_once 'Zend/Mail.php';
require_once 'Zend/Mail/Transport/Smtp.php';
try {
$config = array('ssl' => 'ssl',
'port' => 465,
'auth' => 'login',
'host' => '127.0.0.1',
'username' => 'username#gmail.com',
'password' => 'password');
$transport = new Zend_Mail_Transport_Smtp('smtp.gmail.com', $config);
Zend_Mail::setDefaultTransport($transport);
$mail = new Zend_Mail();
$mail->setSubject("Quotation LL Sports Exim");
$body="Dear Sir/Madam<br>Kindly find the attached Quotation and give us your Feed BAck";
$mail->setBodyHtml($body);
foreach ($emails as $email):
$mail->addTo($email);
endforeach;
var_dump($emails);
if($qid!=""):
$fullBaseUrl = getcwd();
$full_path = $fullBaseUrl . "\\pdfs\\" .$qid.".pdf";
$content = file_get_contents($full_path); // e.g. ("attachment/abc.pdf")
$attachment = new Zend_Mime_Part($content);
$attachment->type = 'application/pdf';
$attachment->disposition = Zend_Mime::DISPOSITION_ATTACHMENT;
$attachment->encoding = Zend_Mime::ENCODING_BASE64;
$attachment->filename ="quotation.pdf"; // name of file
$mail->addAttachment($attachment);
endif;
$mail->send($transport);
return true;
} catch (Zend_Exception $e) {
echo "Caught exception: " . get_class($e) . "\n";
echo "Message: " . $e->getMessage() . "\n";
exit;
// Other code to recover from the error
}
}
Please let me know where I did wrong?
Thanks in advance.