{"id":5166,"date":"2019-11-09T12:44:03","date_gmt":"2019-11-09T07:14:03","guid":{"rendered":"https:\/\/pheonixsolutions.com\/blog\/?p=5166"},"modified":"2019-11-09T12:44:10","modified_gmt":"2019-11-09T07:14:10","slug":"how-to-debug-in-codeigniter","status":"publish","type":"post","link":"https:\/\/pheonixsolutions.com\/blog\/how-to-debug-in-codeigniter\/","title":{"rendered":"How to debug in Codeigniter"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\">How to debug in Codeigniter<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">Date : 09\/11\/2019<\/h4>\n\n\n\n<h4 class=\"wp-block-heading\">Introduction<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">We can use functions like <code>echo,<\/code> <code>print_r(), var_dump()<\/code> or <code>log_message()<\/code> to print values both in log files and also in browser. Other than log_message() other print methods will not print values in log_message. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>echo<\/code> &#8211; used to simply display the content.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>print_r() <\/code>&#8211; used to display value in array format.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>var_dump()<\/code> &#8211; same like print_r(). But in slightly different and clear way such datatype of every values and size of array if the variable passed to <code>var_dump()<\/code> has any array.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>log_message()<\/code> &#8211; used to print messages only in log files.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Set-up for log_message()<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">You need to set your $config[&#8216;log_threshold&#8217;] in file config.php since by default it&#8217;s 0 (no logs) <\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>0 = Disables logging, Error logging TURNED OFF<\/li><li>1 = Error Messages (including PHP errors)<\/li><li>2 = Debug Messages<\/li><li>3 = Informational Messages<\/li><li>4 = All Messages<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">If you have set level to 2, below example print<strong> the output in the log file you have mention.<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">log_message(&#8216;debug&#8217;, print_r(&#8216;<strong>debugging enabled<\/strong>&#8216;)); <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">=&gt; <code>DEBUG - 2019-11-08 15:41:48 --&gt; debugging enabled<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Set-Up for var_dump() :<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">We can use echo or var_dump() in yourcontroller.php or yourmodel.php file to display it the browser. It can be helpful to check the outputs of those files in the browser itself.<br><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example, You are sending request from front-end with ajax. Whether the call is success or not, you can see successful <code>var_dump()<\/code> operations from your controller and model file in the browser itself. To see those successful outputs, do something like the follow.<br><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">$.ajax({<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">url : &#8216;your_url&#8217;,<br>data : &#8216;id= xxx&#8217;,<br>type : &#8216;post&#8217;,<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">success : function(response){<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">$(&#8216;html&#8217;).html(response);<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">},<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">error : function(error){<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">$(&#8216;html&#8217;).html(error);<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">}<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">});<br><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you used echo or var_dump() in Controller or Model file, the above code will display all the echo and var_dumps() values of controller and model file&#8217;s <code>var_dump()<\/code> and <code>echo<\/code> outputs in the browser. By doing this, you can verify every operation give your output or anything went wrong quickly. <\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Conclusion<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Thank you  for using pheonixsolutions. If you find it useful, share it with your friends.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>How to debug in Codeigniter Date : 09\/11\/2019 Introduction We can use functions like echo, print_r(), var_dump() or log_message() to [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[1022],"tags":[605,273],"class_list":["post-5166","post","type-post","status-publish","format-standard","hentry","category-web-architecture","tag-codeigniter-framework","tag-php","psol-cat-web-architecture"],"jetpack_publicize_connections":[],"jetpack_shortlink":"https:\/\/wp.me\/phn2x7-1lk","jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/5166","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/comments?post=5166"}],"version-history":[{"count":0,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/5166\/revisions"}],"wp:attachment":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=5166"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=5166"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=5166"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}