I am sending data from controller to view in codeigniter, everything works fine until i pass a data that is $this->data['mustvisitedcities'].
This is the controller
public function index() {
$this->data['ptype'] = "index";
if($this->validlang){
$slug = $this->uri->segment(3);
}else{
$slug = $this->uri->segment(2);
}
if (!empty ($slug)) {
$this->dests_lib->set_destid($slug);
$this->data['details'] = $this->dests_lib->dest_details();
$this->data['title'] = $this->dests_lib->title;
$this->data['thumbnail'] = $this->dests_lib->thumbnail;
$this->data['date'] = $this->dests_lib->date;
$res = $this->Settings_model->get_contact_page_details();
$this->data['phone'] = $res[0]->contact_phone;
$this->data['langurl'] = base_url()."destinations/{langid}/".$this->dests_lib->slug;
$mustvisitedlocid = $this->data['details'][0]->related_cities;
$this->data['mustvisitedcities'] = $this->dests_lib->get_mustvisitedcity($mustvisitedlocid);
$this->setMetaData($this->data['details'][0]->location_meta_title,$this->data['details'][0]->location_meta_desc,$this->data['details'][0]->location_meta_keywords);
$this->theme->view('modules/destinations/dest_details', $this->data, $this);
}
else {
$this->listing();
}
}
problem is passing $this->data['mustvisitedcities'] throw some error that i am not able to find. when i remove this then everything works fine.
I tried to print this variable and data is there as i want but its just impossible for me to pass this to view.
when i print $this->data['mustvisitedcities'], i get following result
Array ( [0] => stdClass Object ( [id] => 2642 [location] => Irkutsk [slug] => https://www.happyvoyaging.com/destinations/Irkutsk [thumbnail] => https://www.happyvoyaging.com/uploads/images/locations/thumbs/ ) [1] => stdClass Object ( [id] => 3067 [location] => Krasnojarsk [slug] => https://www.happyvoyaging.com/destinations/Krasnojarsk [thumbnail] => https://www.happyvoyaging.com/uploads/images/locations/thumbs/ ) [2] => stdClass Object ( [id] => 3554 [location] => Saint Petersburg [slug] => https://www.happyvoyaging.com/destinations/Saint Petersburg [thumbnail] => https://www.happyvoyaging.com/uploads/images/locations/thumbs/ ) [3] => stdClass Object ( [id] => 4081 [location] => Murmansk [slug] => https://www.happyvoyaging.com/destinations/Murmansk [thumbnail] => https://www.happyvoyaging.com/uploads/images/locations/thumbs/ ) [4] => stdClass Object ( [id] => 4131 [location] => Moscow [slug] => https://www.happyvoyaging.com/destinations/Moscow [thumbnail] => https://www.happyvoyaging.com/uploads/images/locations/thumbs/ ) )
in view i am fetching above data as
<?php foreach($mustvisitedcities as $item){ ?>
<div>
<div>
<a href="<?php echo $item->slug;?>">
<div>
<div>
<div class="lazyload-wrapper">
<img src="<?php echo $item->thumbnail;?>" alt="<?php echo character_limiter($item->location,30);?>" data-pin-nopin="true">
</div>
</div>
</div>
<div>
<h4 color="#121416"><?php echo character_limiter($item->location,30);?></h4>
</div>
</a>
</div>
</div>
<?php } ?>
When i print entire $this->data, i get this
Array ( [ptype] => index [details] => Array ( [0] => stdClass Object ( [id] => 9416 [country] => Russia [location] => Russia [location_slug] => [location_desc] => [location_meta_title] => Russia [location_meta_keywords] => [location_meta_desc] => [location_img] => [location_thumb] => 502844_russian.jpg [related_cities] => 2642,3067,3554,4081,4131 [preferred_cities] => [latitude] => 61.5240 [longitude] => 105.3188 [user] => [status] => Yes ) ) [title] => Russia [thumbnail] => https://www.happyvoyaging.com/uploads/images/locations/thumbs/502844_russian.jpg [date] => [phone] => +918860709211 [langurl] => https://www.happyvoyaging.com/destinations/{langid}/Russia [mustvisitedcities] => Array ( [0] => stdClass Object ( [id] => 2642 [location] => Irkutsk [slug] => https://www.happyvoyaging.com/destinations/Irkutsk [thumbnail] => https://www.happyvoyaging.com/uploads/images/locations/thumbs/ ) [1] => stdClass Object ( [id] => 3067 [location] => Krasnojarsk [slug] => https://www.happyvoyaging.com/destinations/Krasnojarsk [thumbnail] => https://www.happyvoyaging.com/uploads/images/locations/thumbs/ ) [2] => stdClass Object ( [id] => 3554 [location] => Saint Petersburg [slug] => https://www.happyvoyaging.com/destinations/Saint Petersburg [thumbnail] => https://www.happyvoyaging.com/uploads/images/locations/thumbs/ ) [3] => stdClass Object ( [id] => 4081 [location] => Murmansk [slug] => https://www.happyvoyaging.com/destinations/Murmansk [thumbnail] => https://www.happyvoyaging.com/uploads/images/locations/thumbs/ ) [4] => stdClass Object ( [id] => 4131 [location] => Moscow [slug] => https://www.happyvoyaging.com/destinations/Moscow [thumbnail] => https://www.happyvoyaging.com/uploads/images/locations/thumbs/ ) ) [pageTitle] => Russia [metadescription] => Book sightseeing tours, attractions, visa and experiences in 500+ destinations at guaranteed low prices with handpicked reliable suppliers. [metakeywords] => Tours, Sightseeing and Things To Do around the World, Russia Visa agent in India, Russia Visa agent Delhi, Dubai Visa agent Delhi, Dubai Visa agent India )
Try using :
$data[‘variablename’] = $examplevariable;
$data[‘variablename2’] = “This is a test”;
$this->load->view(‘phpname’, $data);
To call it on view :
Related
I have this blade view that retrieves data from a controller. So far, so good. Now I need to export this view to a PDF, but can't pass any variables.
Let's see some code:
My controller:
public function nota(Request $request)
{
$pessoa = Contrato::where('user_id', '=', Auth::user()->id)->first();
$contrato = Contrato::where('user_id', '=', Auth::user()->id)
->where('disponivel', '=', 1)->get();
$endereco = Endereco::where('user_id', '=', Auth::user()->id)->first();
$consorciado = Auth::user();
$data = [$pessoa, $contrato, $endereco, $consorciado];
$pdf = PDF::loadView('contemplado.notaPromissoria', compact('data'));
return $pdf->download('notapromissoria.pdf');
// return view('contemplado.notaPromissoria')->withPessoa($pessoa)->withContrato($contrato)->withEndereco($endereco)->withConsorciado(Auth::user());
}
My blade:
#extends('contemplado.app')
#section('content')
<div class="container m-t-50">
<div class="container">
<h4>Nota Promissória</h4>
<div class="card">
<div class="card-body">
<div class="row">
<div class="col-sm-6">
{{-- Emitente: <strong>{{ $consorciado->name }}</strong> --}}
</div>
<div class="col-sm-6">
Contrato número:
#foreach($contrato as $c)
<strong>{{ $c->contrato }}</strong>
#endforeach
</div>
</div>
#foreach($contrato as $c)
<div class="row">
<div class="col-sm-6">Percentual Vincendo: <strong>{{ $c->percQuitacao }} %</strong></div>
<div class="col-sm-6">Grupo: <strong>{{ $c->grupo }}</strong>, Cota: <strong>{{ $c->cota }}</strong></div>
</div>
#endforeach
#foreach($contrato as $c)
Valor: <strong>R$ {{ $c->valor }}</strong><br>
<div class="row">
<div class="col-sm-4">
Aos dias
<hr class="m-t-10 new3">
</div>
<div class="col-sm-4">
do mês de
<hr class="m-t-10 new3">
</div>
<div class="col-sm-4">
de
<hr class="m-t-10 new3">
</div>
</div>
<div class="row m-t-10">
<div class="col-sm-12">
, pagarei por esta <strong>NOTA PROMISSÓRIA</strong> ao <strong>PRIMO ROSSI ADM DE CONSÓRCIO LTDA</strong> ou à sua ordem a quantia de:<small><i>(por extenso)</i></small>
<hr class="m-t-10 new3"> em moeda corrente, no valor correspondente ao saldo devedor a data de:{DATA DO DIA DA EMISSÃO}
</div>
</div>
#endforeach
<hr>
<div class="row m-b-20">
<div class="col-sm-12">
<strong>Esta Nota Promissória é inegociável, conforme contrato de alienação fiduciária e/ou escritura pública de confissão de dívida com garantia hipotecária, a qual está vinculada, fazendo parte integrante e inseparável dos mesmos</strong>
</div>
</div>
</div>
<div class="card-body">
<div class="row">
<div class="col-sm-6">
{{-- Nome: <strong>{{ $consorciado->name }}</strong> --}}
</div>
<div class="col-sm-6">
{{-- CPF/CNPJ: <strong>{{ $consorciado->cpfCnpj }}</strong> --}}
</div>
</div>
<div class="row">
<div class="col-sm-12">
Endereço: <strong>{{ $endereco->logradouro }}</strong>, <strong>{{ $endereco->numero }}</strong>
</div>
</div>
<div class="row">
<div class="col-sm-6">
Cidade: <strong>{{ $endereco->municipio }}</strong>
</div>
<div class="col-sm-6">
Estado: <strong>{{ $endereco->uf }}</strong>
</div>
</div>
<div class="row">
<div class="col-sm-6">
CEP: <strong>{{ $endereco->cep }}</strong>
</div>
<div class="col-sm-6">
Telefones: <strong>{{ $endereco->telefone }}</strong> <strong>{{ $endereco->celular }}</strong>
</div>
</div>
<div class="row">
<div class="col-sm-12">
Assinatura Emitente:<br>
<hr class="m-t-10 new3">
</div>
</div>
</div>
<div class="card-body">
<div class="card-tile">
<strong>Primeiro Avalista</strong>
</div>
<div class="row">
<div class="col-sm-6">
Nome:
<hr class="m-t-10 new3">
</div>
<div class="col-sm-6">
CPF:
<hr class="m-t-10 new3">
</div>
</div>
<div class="row">
<div class="col-sm-12">
Endereço:
<hr class="m-t-10 new3">
</div>
</div>
<div class="row">
<div class="col-sm-6">
Cidade:
<hr class="m-t-10 new3">
</div>
<div class="col-sm-6">
Estado:
<hr class="m-t-10 new3">
</div>
</div>
<div class="row">
<div class="col-sm-6">
CEP:
<hr class="m-t-10 new3">
</div>
<div class="col-sm-6">
Telefones:
<hr class="m-t-10 new3">
</div>
</div>
<div class="row">
<div class="col-sm-12">
Assinatura do Avalista:<br>
<hr class="m-t-10 new3">
</div>
</div>
<div class="row">
<div class="col-sm-6">
Nome do Cônjuge:
<hr class="m-t-10 new3">
</div>
<div class="col-sm-6">
CPF do Cônjuge:
<hr class="m-t-10 new3">
</div>
</div>
<div class="row m-t-10">
<div class="col-sm-12">
Assinatura do Cônjuge do Avalista:<br>
<hr class="m-t-10 new3">
</div>
</div>
<hr>
<div class="card-tile">
<strong>Segundo Avalista</strong>
</div>
<div class="row">
<div class="col-sm-6">
Nome:
<hr class="m-t-10 new3">
</div>
<div class="col-sm-6">
CPF:
<hr class="m-t-10 new3">
</div>
</div>
<div class="row">
<div class="col-sm-12">
Endereço:
<hr class="m-t-10 new3">
</div>
</div>
<div class="row">
<div class="col-sm-6">
Cidade:
<hr class="m-t-10 new3">
</div>
<div class="col-sm-6">
Estado:
<hr class="m-t-10 new3">
</div>
</div>
<div class="row">
<div class="col-sm-6">
CEP:
<hr class="m-t-10 new3">
</div>
<div class="col-sm-6">
Telefones:
<hr class="m-t-10 new3">
</div>
</div>
<div class="row">
<div class="col-sm-12">
Assinatura do Avalista:<br>
<hr class="m-t-10 new3">
</div>
</div>
<div class="row">
<div class="col-sm-6">
Nome do Cônjuge:
<hr class="m-t-10 new3">
</div>
<div class="col-sm-6">
CPF do Cônjuge:
<hr class="m-t-10 new3">
</div>
</div>
<div class="row m-t-10">
<div class="col-sm-12">
Assinatura do Cônjuge do Avalista:<br>
<hr class="m-t-10 new3">
</div>
</div>
</div>
</div>
</div>
</div>
#endsection
#section('scripts')
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script>
var vue = new Vue({
el: '#app',
data: {
isLoading: false
},
});
</script>
#endsection
The print_r result:
Array ( [0] => App\Contrato Object ( [guarded:protected] => Array ( ) [connection:protected] => mysql [table:protected] => contratos [primaryKey:protected] => id [keyType:protected] => int [incrementing] => 1 [with:protected] => Array ( ) [withCount:protected] => Array ( ) [perPage:protected] => 15 [exists] => 1 [wasRecentlyCreated] => [attributes:protected] => Array ( [id] => 459 [user_id] => 842 [contrato] => 851717 [disponivel] => 1 [grupo] => 06271 [cota] => 871 [valor] => 34163 [conta_conjunta] => [novoSegmento] => [originalSegmento] => 06271 [completo] => [novoUsado] => 1 [pessoa] => F [descricao] => 50% COBALT 1.8 (COD.9062) [data_entrega] => 1970-01-01 00:00:01 [data_contemplacao] => 2019-11-12 00:00:00 [cep] => 38407526 [codFormaPagto] => 3 [codigo_bem] => 9075 [codPlanoCota] => 70 [data_cancelamento] => 1970-01-01 00:00:01 [dataProxReuniao] => 2020-01-14 00:00:00 [descSituacaoCobranca] => Normal [faseCobranca] => N000 [numSeq] => 0 [percQuitacao] => 26.5461 [valorQuitacao] => 10505.54 [percTotalPago] => 73.4539 [percTotalPendente] => 0 [situacaoCobranca] => N [garagem] => [created_at] => 2019-12-19 12:55:07 [updated_at] => 2019-12-19 12:55:21 ) [original:protected] => Array ( [id] => 459 [user_id] => 842 [contrato] => 851717 [disponivel] => 1 [grupo] => 06271 [cota] => 871 [valor] => 34163 [conta_conjunta] => [novoSegmento] => [originalSegmento] => 06271 [completo] => [novoUsado] => 1 [pessoa] => F [descricao] => 50% COBALT 1.8 (COD.9062) [data_entrega] => 1970-01-01 00:00:01 [data_contemplacao] => 2019-11-12 00:00:00 [cep] => 38407526 [codFormaPagto] => 3 [codigo_bem] => 9075 [codPlanoCota] => 70 [data_cancelamento] => 1970-01-01 00:00:01 [dataProxReuniao] => 2020-01-14 00:00:00 [descSituacaoCobranca] => Normal [faseCobranca] => N000 [numSeq] => 0 [percQuitacao] => 26.5461 [valorQuitacao] => 10505.54 [percTotalPago] => 73.4539 [percTotalPendente] => 0 [situacaoCobranca] => N [garagem] => [created_at] => 2019-12-19 12:55:07 [updated_at] => 2019-12-19 12:55:21 ) [changes:protected] => Array ( ) [casts:protected] => Array ( ) [dates:protected] => Array ( ) [dateFormat:protected] => [appends:protected] => Array ( ) [dispatchesEvents:protected] => Array ( ) [observables:protected] => Array ( ) [relations:protected] => Array ( ) [touches:protected] => Array ( ) [timestamps] => 1 [hidden:protected] => Array ( ) [visible:protected] => Array ( ) [fillable:protected] => Array ( ) ) [1] => Illuminate\Database\Eloquent\Collection Object ( [items:protected] => Array ( [0] => App\Contrato Object ( [guarded:protected] => Array ( ) [connection:protected] => mysql [table:protected] => contratos [primaryKey:protected] => id [keyType:protected] => int [incrementing] => 1 [with:protected] => Array ( ) [withCount:protected] => Array ( ) [perPage:protected] => 15 [exists] => 1 [wasRecentlyCreated] => [attributes:protected] => Array ( [id] => 459 [user_id] => 842 [contrato] => 851717 [disponivel] => 1 [grupo] => 06271 [cota] => 871 [valor] => 34163 [conta_conjunta] => [novoSegmento] => [originalSegmento] => 06271 [completo] => [novoUsado] => 1 [pessoa] => F [descricao] => 50% COBALT 1.8 (COD.9062) [data_entrega] => 1970-01-01 00:00:01 [data_contemplacao] => 2019-11-12 00:00:00 [cep] => 38407526 [codFormaPagto] => 3 [codigo_bem] => 9075 [codPlanoCota] => 70 [data_cancelamento] => 1970-01-01 00:00:01 [dataProxReuniao] => 2020-01-14 00:00:00 [descSituacaoCobranca] => Normal [faseCobranca] => N000 [numSeq] => 0 [percQuitacao] => 26.5461 [valorQuitacao] => 10505.54 [percTotalPago] => 73.4539 [percTotalPendente] => 0 [situacaoCobranca] => N [garagem] => [created_at] => 2019-12-19 12:55:07 [updated_at] => 2019-12-19 12:55:21 ) [original:protected] => Array ( [id] => 459 [user_id] => 842 [contrato] => 851717 [disponivel] => 1 [grupo] => 06271 [cota] => 871 [valor] => 34163 [conta_conjunta] => [novoSegmento] => [originalSegmento] => 06271 [completo] => [novoUsado] => 1 [pessoa] => F [descricao] => 50% COBALT 1.8 (COD.9062) [data_entrega] => 1970-01-01 00:00:01 [data_contemplacao] => 2019-11-12 00:00:00 [cep] => 38407526 [codFormaPagto] => 3 [codigo_bem] => 9075 [codPlanoCota] => 70 [data_cancelamento] => 1970-01-01 00:00:01 [dataProxReuniao] => 2020-01-14 00:00:00 [descSituacaoCobranca] => Normal [faseCobranca] => N000 [numSeq] => 0 [percQuitacao] => 26.5461 [valorQuitacao] => 10505.54 [percTotalPago] => 73.4539 [percTotalPendente] => 0 [situacaoCobranca] => N [garagem] => [created_at] => 2019-12-19 12:55:07 [updated_at] => 2019-12-19 12:55:21 ) [changes:protected] => Array ( ) [casts:protected] => Array ( ) [dates:protected] => Array ( ) [dateFormat:protected] => [appends:protected] => Array ( ) [dispatchesEvents:protected] => Array ( ) [observables:protected] => Array ( ) [relations:protected] => Array ( ) [touches:protected] => Array ( ) [timestamps] => 1 [hidden:protected] => Array ( ) [visible:protected] => Array ( ) [fillable:protected] => Array ( ) ) ) ) [2] => App\Endereco Object ( [connection:protected] => mysql [table:protected] => enderecos [primaryKey:protected] => id [keyType:protected] => int [incrementing] => 1 [with:protected] => Array ( ) [withCount:protected] => Array ( ) [perPage:protected] => 15 [exists] => 1 [wasRecentlyCreated] => [attributes:protected] => Array ( [id] => 395 [user_id] => 842 [logradouro] => R DA REALIZAÇÃO [numero] => 760 [bairro] => JOANA DARC [municipio] => [uf] => MG [complemento] => [telefone] => (34) 9885-1104 [celular] => (11) 91234-5678 [cep] => 38407-526 [correspondencia] => [tempoResidencia] => 10 [created_at] => 2019-12-19 12:55:12 [updated_at] => 2019-12-19 13:03:50 ) [original:protected] => Array ( [id] => 395 [user_id] => 842 [logradouro] => R DA REALIZAÇÃO [numero] => 760 [bairro] => JOANA DARC [municipio] => [uf] => MG [complemento] => [telefone] => (34) 9885-1104 [celular] => (11) 91234-5678 [cep] => 38407-526 [correspondencia] => [tempoResidencia] => 10 [created_at] => 2019-12-19 12:55:12 [updated_at] => 2019-12-19 13:03:50 ) [changes:protected] => Array ( ) [casts:protected] => Array ( ) [dates:protected] => Array ( ) [dateFormat:protected] => [appends:protected] => Array ( ) [dispatchesEvents:protected] => Array ( ) [observables:protected] => Array ( ) [relations:protected] => Array ( ) [touches:protected] => Array ( ) [timestamps] => 1 [hidden:protected] => Array ( ) [visible:protected] => Array ( ) [fillable:protected] => Array ( ) [guarded:protected] => Array ( [0] => * ) ) [3] => App\User Object ( [fillable:protected] => Array ( [0] => name [1] => cpfCnpj [2] => password ) [hidden:protected] => Array ( [0] => password [1] => remember_token ) [casts:protected] => Array ( [email_verified_at] => datetime ) [guarded:protected] => Array ( ) [additional_attributes] => Array ( [0] => locale ) [connection:protected] => mysql [table:protected] => users [primaryKey:protected] => id [keyType:protected] => int [incrementing] => 1 [with:protected] => Array ( ) [withCount:protected] => Array ( ) [perPage:protected] => 15 [exists] => 1 [wasRecentlyCreated] => [attributes:protected] => Array ( [id] => 842 [role_id] => 2 [fiador_id] => [name] => JOSE CARLOS SOARES [email] => email#pwa.com [avatar] => users/default.png [email_verified_at] => [password] => $2y$10$EqgjoWwYe2FBLDkJALqUm.kNLQCjovdEuRrtIhOfEV9lvqM2LxP8G [remember_token] => [settings] => [cc] => [unidade] => [matricula] => [departamento] => [equipe] => [cep] => [cargo] => [uf] => [telefoneComercial] => [celular_comercial] => [telefone] => [nascimento] => [seriePagSeguro] => [senhaMaquininha] => [numeroArmario] => [precisaAssEletronica] => [whatsapp] => [novaAssinatura] => [cpfCnpj] => 00445341670 [IE] => [estado_civil_id] => 1 [renda] => 2 [tipoBeneficio] => [numeroBeneficio] => [tempoBeneficio] => [atividade_principal] => [atividades_secundarias] => [capital_social] => [data_situacao] => [data_situacao_especial] => [fantasia] => [motivo_situacao] => [natureza_juridica] => [porte] => [status] => [tipo] => [ultima_atualizacao] => [receita] => [idERP] => 1 [sms] => [adesao] => [created_at] => 2019-12-19 12:55:07 [updated_at] => 2019-12-19 13:59:20 ) [original:protected] => Array ( [id] => 842 [role_id] => 2 [fiador_id] => [name] => JOSE CARLOS SOARES [email] => email#pwa.com [avatar] => users/default.png [email_verified_at] => [password] => $2y$10$EqgjoWwYe2FBLDkJALqUm.kNLQCjovdEuRrtIhOfEV9lvqM2LxP8G [remember_token] => [settings] => [cc] => [unidade] => [matricula] => [departamento] => [equipe] => [cep] => [cargo] => [uf] => [telefoneComercial] => [celular_comercial] => [telefone] => [nascimento] => [seriePagSeguro] => [senhaMaquininha] => [numeroArmario] => [precisaAssEletronica] => [whatsapp] => [novaAssinatura] => [cpfCnpj] => 00445341670 [IE] => [estado_civil_id] => 1 [renda] => 2 [tipoBeneficio] => [numeroBeneficio] => [tempoBeneficio] => [atividade_principal] => [atividades_secundarias] => [capital_social] => [data_situacao] => [data_situacao_especial] => [fantasia] => [motivo_situacao] => [natureza_juridica] => [porte] => [status] => [tipo] => [ultima_atualizacao] => [receita] => [idERP] => 1 [sms] => [adesao] => [created_at] => 2019-12-19 12:55:07 [updated_at] => 2019-12-19 13:59:20 ) [changes:protected] => Array ( ) [dates:protected] => Array ( ) [dateFormat:protected] => [appends:protected] => Array ( ) [dispatchesEvents:protected] => Array ( ) [observables:protected] => Array ( ) [relations:protected] => Array ( [role] => TCG\Voyager\Models\Role Object ( [guarded:protected] => Array ( ) [connection:protected] => mysql [table:protected] => roles [primaryKey:protected] => id [keyType:protected] => int [incrementing] => 1 [with:protected] => Array ( ) [withCount:protected] => Array ( ) [perPage:protected] => 15 [exists] => 1 [wasRecentlyCreated] => [attributes:protected] => Array ( [id] => 2 [name] => user [display_name] => Normal User [created_at] => 2019-06-10 14:53:44 [updated_at] => 2019-06-10 14:53:44 ) [original:protected] => Array ( [id] => 2 [name] => user [display_name] => Normal User [created_at] => 2019-06-10 14:53:44 [updated_at] => 2019-06-10 14:53:44 ) [changes:protected] => Array ( ) [casts:protected] => Array ( ) [dates:protected] => Array ( ) [dateFormat:protected] => [appends:protected] => Array ( ) [dispatchesEvents:protected] => Array ( ) [observables:protected] => Array ( ) [relations:protected] => Array ( ) [touches:protected] => Array ( ) [timestamps] => 1 [hidden:protected] => Array ( ) [visible:protected] => Array ( ) [fillable:protected] => Array ( ) ) [roles] => Illuminate\Database\Eloquent\Collection Object ( [items:protected] => Array ( ) ) ) [touches:protected] => Array ( ) [timestamps] => 1 [visible:protected] => Array ( ) [rememberTokenName:protected] => remember_token ) ) 1
The error:
Undefined variable: contrato (View: /Users/marcellopato/Sites/primorossi/resources/views/contemplado/notaPromissoria.blade.php)
As you can see, I want to pass those types of data to the PDF. It works well when passing to view, but I can't do the export to PDF.
Any hints?
Thanks in advance!
You are not passing an associative array where the keys are what you want the variables to be named in the view:
PDF::loadView(..., [
'pessoa' => $pessoa,
'contrato' => $contrato,
'endereco' => $endereco,
'consorciado' => $consorciado,
]);
OR using compact:
PDF::loadView(..., compact('pessoa', 'contrato', 'endereco', 'consorciado'));
With what you currently have, even if it was a regular view, you would have to access all the variables from $data: $data[0], $data[1], etc., as they are not named because you have a zero index array, not an associative array. You are passing an array like so:
['data' => [$pessoa, $contrator, ...]]
Solved that issue by exporting the view AFTER passing variables and then applying CSS!
i've used the following models: invoice, invoice_product and the pro_stock as listed bellow
public function items()
{
return $this->hasMany(invoice_product::class);
}
which return the invoice products, then
public function products(){
return $this->belongsTo(prodStock::class);
}
which gets the ids from stock table and the invoice controller
public function show($id)
{
$items = invoice_product::find($id);
$invoice = invoice::with(['items.products'])
->findOrFail($id);
return view('pages.InvoiceDetails', compact('invoice'));
}
in my view blade i return
#foreach($invoice->items as $item)
<tr>
<td>{{$no++}}</td>
<td class="table-name">{{$item->products->pro_name}}</td>
<td class="table-price">{{$item->unit_price}}</td>
<td class="table-qty">{{$item->qty}}</td>
<td class="table-total text-right">{{$item->total}}</td>
</tr>
#endforeach
and its ruturns
Trying to get property of non-object (View:
Once ive tested using print_r($invoice->toArray())
returned me these data, i want to replaced pro_stock_id with its name
[items] => Array ( [0] => Array ( [id] => 130 [invoice_id] => 87 [pro_stock_id] => 7 [unit_price] => 200 [qty] => 1 [total] => 200 [created_at] => 2019-11-27 09:32:20 [updated_at] => 2019-11-27 09:32:20 [products] => ) [1] => Array ( [id] => 131 [invoice_id] => 87 [pro_stock_id] => 8 [unit_price] => 300 [qty] => 12 [total] => 3600 [created_at] => 2019-11-27 09:32:20 [updated_at] => 2019-11-27 09:32:20 [products] => ) [2] => Array ( [id] => 132 [invoice_id] => 87 [pro_stock_id] => 4 [unit_price] => 300 [qty] => 1 [total] => 300 [created_at] => 2019-11-27 09:32:20 [updated_at] => 2019-11-27 09:32:20 [products] => ) ) )
My controller like this :
public function index(Request $request)
{
$param = $request->all();
$data = $this->itemDetailRepository->getData($param);
return view('item-detail.index', compact('param'))
->withItems(count($data)>0?$data:null);
}
If I debug $data or in laravel (dd($data)), the result like this :
So the array $data is collection and pagination like that
If I click in the attributes section, it display like this :
#attributes: array:5 [▼
"item_number" => "AB-0001"
"total_quantity" => "1000"
"location-a" => "500"
"location-b" => "500"
]
So the array data is there
In the view blade laravel like this :
<table>
<tr>
<th>ITEM NUMBER</th>
<th>TOTAL QUANTITY</th>
<th>LOCATION-A</th>
<th>LOCATION-B</th>
</tr>
#foreach($items as $item)
<tr>
<td>{{ $item->item_number }}</td>
<td>{{ $item->total_quantity }}</td>
<td>{{ $item['location-a'] }}</td>
<td>{{ $item['location-b'] }}</td>
</tr>
#endforeach
</table>
It works. But my key of the array is dynamic. The key can change
So the array can change like this :
#attributes: array:5 [▼
"item_number" => "AB-0001"
"total_quantity" => "500"
"location-a" => "500"
]
Or can change like this :
#attributes: array:5 [▼
"item_number" => "AB-0001"
"total_quantity" => "1500"
"location-a" => "500"
"location-b" => "500"
"location-c" => "500"
]
So the location is dynamic
How do I set it in the laravel view blade so that it can adjust to dynamic arrays?
Update
If I echo '<pre>';print_r($data);'</pre>';die();, the result like this :
Illuminate\Pagination\LengthAwarePaginator Object
(
[total:protected] => 2428
[lastPage:protected] => 1214
[items:protected] => Illuminate\Database\Eloquent\Collection Object
(
[items:protected] => Array
(
[0] => App\Models\ItemDetail Object
(
[table:protected] => items_details
[fillable:protected] => Array
(
[0] => item_number
[1] => quantity
...
)
[connection:protected] => mysql
[primaryKey:protected] => id
[keyType:protected] => int
[incrementing] => 1
[with:protected] => Array
(
)
[withCount:protected] => Array
(
)
[perPage:protected] => 15
[exists] => 1
[wasRecentlyCreated] =>
[attributes:protected] => Array
(
[item_number] => AB-0001
[total_quantity] => 1000
[location-a] => 500
[location-b] => 500
)
[original:protected] => Array
(
[item_number] => AB-0001
[total_quantity] => 1000
[location-a] => 500
[location-b] => 500
)
[changes:protected] => Array
(
)
[casts:protected] => Array
(
)
[dates:protected] => Array
(
)
[dateFormat:protected] =>
[appends:protected] => Array
(
)
[dispatchesEvents:protected] => Array
(
)
[observables:protected] => Array
(
)
[relations:protected] => Array
(
)
[touches:protected] => Array
(
)
[timestamps] => 1
[hidden:protected] => Array
(
)
[visible:protected] => Array
(
)
[guarded:protected] => Array
(
[0] => *
)
)
[1] => App\Models\ItemDetail Object
(
[table:protected] => items_details
[fillable:protected] => Array
(
[0] => item_number
[1] => quantity
...
)
[connection:protected] => mysql
[primaryKey:protected] => id
[keyType:protected] => int
[incrementing] => 1
[with:protected] => Array
(
)
[withCount:protected] => Array
(
)
[perPage:protected] => 15
[exists] => 1
[wasRecentlyCreated] =>
[attributes:protected] => Array
(
[item_number] => AB-0002
[total_quantity] => 1500
[location-a] => 1000
[location-b] => 500
)
[original:protected] => Array
(
[item_number] => AB-0002
[total_quantity] => 1500
[location-a] => 1000
[location-b] => 500
)
[changes:protected] => Array
(
)
[casts:protected] => Array
(
)
[dates:protected] => Array
(
)
[dateFormat:protected] =>
[appends:protected] => Array
(
)
[dispatchesEvents:protected] => Array
(
)
[observables:protected] => Array
(
)
[relations:protected] => Array
(
)
[touches:protected] => Array
(
)
[timestamps] => 1
[hidden:protected] => Array
(
)
[visible:protected] => Array
(
)
[guarded:protected] => Array
(
[0] => *
)
)
)
)
[perPage:protected] => 2
[currentPage:protected] => 1
[path:protected] => http://my-project.test/admin/item-detail
[query:protected] => Array
(
)
[fragment:protected] =>
[pageName:protected] => page
)
Try this out:
#php
$counts = array_map('count', $data);
$key = array_flip($counts)[max($counts)];
#endphp
<table>
<tr>
#foreach ($data[$key] as $key => $value)
<th>{{$key}}</th>
#endforeach
</tr>
#foreach($data as $value)
<tr>
#foreach ($value as $key => $value)
<td>{{$value}}</td>
#endforeach
</tr>
#endforeach
</table>
your question is quite confusing, if key is dynamic, you can also send an array with of "key" and can send an array with keys like this
//In your controller
$values = array(
array('item_number' => 'AB-0001','total_quantity' => '500', 'location-a' => '500'),
array('item_number' => 'AB-0002','total_quantity' => '5000', 'location-a' => '5000'),
array('item_number' => 'AB-0003','total_quantity' => '2000', 'location-a' => '2000'),
);
$data =
[
'keys' => ['item_number', 'total_quantity', 'location_a'],
'values' => $values
];
return view('some_blade', $data);
In your blade you can access like this
#foreach($values as $value)
<tr>
#foreach($keys as $k)
<td>{{ $value[$k]; }}</td>
#endforeach
</tr>
#endforeach
hope that helps.
I wanted to fetch the selected value from the database and display it in codeigniter form_dropdown() function but it displays wrong.
Controller:
$type = array(
'options' => array(
'section' => 'Section',
'transaction' => 'Transaction',
'document' => 'Document'
),
'attributes' => array(
'class' => 'form-control'
)
);
View:
<?php echo form_dropdown('type', $type['options'],'', $type['attributes']) ?>
The Screenshot
Try the below code:
Controller:
$this->data['type'] = array(
'name' => 'type_value',
'attributes' => 'class="form-control"',
'value' => (isset($database_type_value) && trim($database_type_value)) ? $database_type_value: $this->input->post('type_value',TRUE), //$database_type_value - value from database
'options_list' => array(
'section' => 'Section',
'transaction' => 'Transaction',
'document' => 'Document'
),
);
View:
<?php echo form_dropdown($type['name'],$type['options_list'],$type['value'],$type['attributes']);?>
I have tried to limit number of rows in textarea to 4 but its giving error
Message: Array to string conversion
this is my code of textarea using helper class
$textarea_options = array('class' => 'form-control','rows' => 4, 'cols' => 40);
echo form_textarea('vc_desc', set_value('vc_desc'), $textarea_options);
setup a $data array instead with all the options
$data = array(
'name' => 'vc_desc',
'id' => 'vc_desc',
'value' => set_value('vc_desc'),
'rows' => '50',
'cols' => '10',
'style' => 'width:50%',
'class' => 'form-control'
);
echo form_textarea($data);
Use rows and cols to get change the height and length of text area in code ignitor.
$data = array('name' => 'SupAddress','value' =>set_value('SupAddress'), 'id'=>'SupAddress', 'class' => 'form-control' ,'readonly' => 'true' ,'rows' => '3', 'cols' => '40');
echo Form_textarea($data);